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
New Developer
Posts: 11
Registered: ‎06-23-2012
My Device: Playbook
My Carrier: Megafon
Accepted Solution

ForeignWindow + OGL example

Hello, can anyone help with working code for foreign window and opengl? I'm new to QML and Qt, hard times to figure that out. There is HelloForeign example, but that's for blitting and article in documentation, but it only covers window initialization. Help and pointers appreciated, especially snippet of code something simple (e.g. rotating triangle).

BlackBerry Development Advisor (Retired)
Posts: 499
Registered: ‎05-07-2012
My Device: developer
My Carrier: developer

Re: ForeignWindow + OGL example

ForeignWindow hands over controls to you.  Once you have OpenGL set up, you have complete control.

 

There are many good OpenGL tutorials on the net, e.g. http://nehe.gamedev.net/

 

Watch the Knowledge Base article space.

 

Stuart

 

 

BlackBerry Development Advisor (Retired)
Posts: 329
Registered: ‎05-07-2012
My Device: BB Alpha
My Carrier: N/A

Re: ForeignWindow + OGL example

Hi there,

You need to do a few things before getting OpenGL working in a ForeignWindow:

1 - you need to initialize your BPS nad OpenGL ES:

bps_initialize();
screen_create_context(&m_screen_cxt, SCREEN_APPLICATION_CONTEXT);
bbutil_init_egl(m_screen_cxt, GL_ES_1, m_width, m_height)

2 - You will then need to build your foreign window (in this case we are setting the ForeignWindow as the root):

float prefWidth = preferredWidth();
float prefHeight = preferredHeight();
m_foreignWindow = ForeignWindow::create().preferredSize(prefWidth, prefHeight);
setRoot(m_foreignWindow);

3 - You will then need to set some window properties for Z-ordering and going the window group:

screen_set_window_property_iv(m_screen_win, SCREEN_PROPERTY_ZORDER, &z);
screen_join_window_group(m_screen_win, m_foreignWindow->windowGroup().toAscii().constData());

4 - Now we can render a triangle:

    //setup projection
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glFrustumf(-0.005, 0.005, -0.01, 0.01, 0.01, 2);

    //setup modelview
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    //clear our buffer
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    //create and draw our triangle
    static GLfloat triangleVertices[9] { -1.0, 0.0, -1.0,     0.0, 1.0, -1.0,     1.0, 0.0, -1.0 };

    glDisable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glVertexPointer(3, GL_FLOAT, 0, triangleVertices);

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 3);

    //pop matrices
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();

5 - After you render pixels to your buffer, you will need to swap your buffers as well:

bbutil_swap();

6 - When you are done with your application loop, you need to terminate a few things:

screen_stop_events(m_screen_cxt);
bps_shutdown();
bbutil_terminate();
screen_destroy_context(m_screen_cxt);

 

Let me know if this helps you. I am looking into building a Knowledge Base article for OpengL setup using a ForeignWindow with some sample code.

 

Cheers,

 

Martin

New Developer
Posts: 11
Registered: ‎06-23-2012
My Device: Playbook
My Carrier: Megafon

Re: ForeignWindow + OGL example

Wow, works. But anyway looking forward for your article :-)
BlackBerry Development Advisor (Retired)
Posts: 329
Registered: ‎05-07-2012
My Device: BB Alpha
My Carrier: N/A

Re: ForeignWindow + OGL example

Great!

 

As mentioned, I have created an knowledge base article on this matter, with sample code. You can find it here under the name "Using OpenGL in a Cascades ForeignWindow":

 

http://supportforums.blackberry.com/t5/Cascades-Development-Knowledge/tkb-p/Cascades%40tkb

 

Cheers,

 

Martin

 

New Developer
Posts: 11
Registered: ‎06-23-2012
My Device: Playbook
My Carrier: Megafon

Re: ForeignWindow + OGL example

Thanks!

 

I'm reading it right now.

 

By the way, I have problems with ForeignWindow, I'm creating child window and attaching it to foreign window's group, but seems it doesn't work as intended; signals not firing. Here is my code with log: https://gist.github.com/29da2dfa829627b2db94

New Developer
Posts: 11
Registered: ‎06-23-2012
My Device: Playbook
My Carrier: Megafon

Re: ForeignWindow + OGL example

hmm, onWindowAttached signal doesn't fire on your program from article too. Seems like it doesn't working at all.

BlackBerry Development Advisor (Retired)
Posts: 329
Registered: ‎05-07-2012
My Device: BB Alpha
My Carrier: N/A

Re: ForeignWindow + OGL example

I don't think I make use of the routine; I'll have to investigate;

 

Martin

Developer
Posts: 44
Registered: ‎05-22-2013
My Device: Blackberry 10
My Carrier: 02

Re: ForeignWindow + OGL example

The link for the article(Using OpenGL in cascade foreign window) no longer exist .  Anyone knows where I can find it,