Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Highlighted
Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x
Accepted Solution

NDK 2.0 + Playbook: Is it ok to combine naitve display usage and OpenGL one?

I'll try to explain what I mean.

Suppose I want to generate text in my app by using bbutil_render_text() from HelloWorldDisplay example and at the same time I want to be able to post bitmaps directly into window buffer, like:

_uint8 *ScreenData;
screen_buffer_t screen_buf;
screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&screen_buf);
screen_get_buffer_property_pv(screen_buf, SCREEN_PROPERTY_POINTER, (void **)&ScreenData);
memcpy(ScreenData, CurrImg);

CurrImg has image bitmap loaded. 

 

 

So I need to initialize stuff first:

screen_create_context(&screen_ctx, SCREEN_APPLICATION_CONTEXT);
screen_create_window(&screen_win, screen_ctx);
// plus some other init steps

And at the same time I see in bbutil_init_egl:

int
bbutil_init_egl(screen_context_t ctx) {
...
rc = screen_create_window(&screen_win, screen_ctx);

 So it also creates a window (screen_win is declared static in bbutil.c), i.e. I have two windows. The Question I am trying to ask here is how do they overlap? Somehow it works but I have weird 'side effects' on image, I suppose I do something wrong.

Retired
Posts: 329
Registered: ‎05-07-2012
My Device: BB Alpha
My Carrier: N/A

Re: NDK 2.0 + Playbook: Is it ok to combine naitve display usage and OpenGL one?

Hi there,

 

You mention that you are able to bring up both rendering method on the same screen -

What do you mean by overlap? Are you trying to render both methods over the same pixel surface?

 

Martin

 

Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: NDK 2.0 + Playbook: Is it ok to combine naitve display usage and OpenGL one?

Hi Martin, thanks for reply, I thought this trhead was born dead -)

I create two windows by screen_create_window. Then one is used like:

screen_get_buffer_property_pv(screen_buf, SCREEN_PROPERTY_POINTER, (void **)&ScreenData);
memcpy(ScreenData, CurrImg);

and another one is used in OpenGL rendering (via eglCreateWindowSurface).

Does this answer your question?

BlackBerry Development Advisor
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: NDK 2.0 + Playbook: Is it ok to combine naitve display usage and OpenGL one?

This sort of thing should be doable.  You should just need to tweak z-order and transparency to stack up the windows appropriately.  And post of course.

 

Cheers,

Sean

Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: NDK 2.0 + Playbook: Is it ok to combine naitve display usage and OpenGL one?

Where can I read about z-order and transparency? On which level is it done egl-GLES or native?

what do you mean by 'post' please?

BlackBerry Development Advisor
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: NDK 2.0 + Playbook: Is it ok to combine naitve display usage and OpenGL one?

This is all covered in the screen library documentation.

searching for SCREEN_PROPERTY_ZORDER led me to this sample code which makes use of multiple windows:

https://developer.blackberry.com/native/reference/com.qnx.doc.screen.lib_ref/topic/cscreen_sample.ht...

 

Cheers,

Sean

Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: NDK 2.0 + Playbook: Is it ok to combine naitve display usage and OpenGL one?

Yes, that worked to some degree - when I use two windows, one is parent (where I do native 'drawing') and another one is a child (where I do OpenGL) in window group, at least these two windows do not mess each other.

One more challenge left - transparency and zorder do not seem to work -( whatever I do, OpenGLES wins (always come on top of Native one).

If you have any idea why please share.

Thanks!

BlackBerry Development Advisor
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: NDK 2.0 + Playbook: Is it ok to combine naitve display usage and OpenGL one?

please share your zorder and transparency code.

did you flush the screen context after applying the transparency and zorder properties?

Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: NDK 2.0 + Playbook: Is it ok to combine naitve display usage and OpenGL one?

in main() function:
	const int usage 		    = SCREEN_USAGE_WRITE;
	const int screen_format 	= SCREEN_FORMAT_RGBA8888;

	screen_create_context(&screen_ctx, SCREEN_APPLICATION_CONTEXT);
        screen_create_window(&screen_win, screen_ctx);
	int count = 0;
	screen_display_t *screen_disps = (screen_display_t *)calloc(count, sizeof(screen_display_t));
	screen_get_context_property_pv(screen_ctx, SCREEN_PROPERTY_DISPLAYS, (void **)screen_disps);
	screen_disp = screen_disps[0];
	free(screen_disps);
        screen_create_window_group(screen_win, strWinGroup);
	int zorder = 0;
	screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ZORDER, &zorder);
        screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage);
        screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_FORMAT, &screen_format);

Here I call Win2Init() function

        screen_flush_context(screen_ctx, SCREEN_WAIT_IDLE);
End of main()

Win2Init(){
        int format = SCREEN_FORMAT_RGBX8888;
        int usage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION;
	screen_context_t screen_ctx;
	screen_create_context(&screen_ctx, SCREEN_APPLICATION_CONTEXT);
        screen_create_window_type(&screen_win_gles, screen_ctx, SCREEN_CHILD_WINDOW);
        screen_join_window_group(screen_win_gles, group);//strWinGroup);
        screen_set_window_property_cv(screen_win_gles, SCREEN_PROPERTY_ID_STRING, strlen(strGLESWinId), strGLESWinId);
	int transparency = SCREEN_TRANSPARENCY_SOURCE_OVER;
	screen_set_window_property_iv(screen_win_gles, SCREEN_PROPERTY_TRANSPARENCY, &transparency);
	int zorder = 1;
	screen_set_window_property_iv(screen_win_gles, SCREEN_PROPERTY_ZORDER, &zorder);
        screen_set_window_property_iv(screen_win_gles, SCREEN_PROPERTY_FORMAT, &format);
        screen_set_window_property_iv(screen_win_gles, SCREEN_PROPERTY_USAGE, &usage);
        ...
}



 

BlackBerry Development Advisor
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: NDK 2.0 + Playbook: Is it ok to combine naitve display usage and OpenGL one?

So if I understand - you're trying to set a native non-gl window to live BEHIND the opengl window?

You should try out the different SCREEN_PROPERTY_TRANSPARENCY modes just to be sure.

Also, you need a screen_flush_context() after setting the properties on screen_win_gles.  You are only flushing your first window's properties.