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
Developer
Posts: 133
Registered: ‎03-28-2011
My Device: BlackBerry 9900 & PlayBook
My Carrier: Bell
Accepted Solution

Qt and OpenGL not rendering

I've implemented the example in the Qt 4.8 SDK under opengl/cube.

 

http://qt.gitorious.org/qt/qt/trees/4.8/examples/opengl/cube

 

I modified it so that it would run on the PlayBook (namely, not using QWindow).

 

It runs great on Ubuntu in Qt Creator. Cross-compiles for the PlayBook just fine, and I can load it on the device and run it, but it doesn't work correctly.

 

Namely, it just displays a blank white screen which turns black when I tap it. You'll notice there are some qDebug() << calls in the initializeGL() function call. I added some QMessageBox calls instead to see if these were being reached, and it seems they are. No idea if the other functions are being completed correctly, still looking into that.

 

Anyone have any ideas of what I may be missing here? Is there a way to actually debug the program, so I can track down the issues myself?


Founder of Pulsecode Inc. and taab
Authomator - Two-factor authentication codes on BlackBerry 10 - http://www.xitijpatel.com/ - Follow @xitijpatel
Is there a helpful or useful post in this thread? Click the thumbs up on it so that other people can find it more easily!
New Developer
Posts: 19
Registered: ‎02-24-2012
My Device: Developer
My Carrier: -

Re: Qt and OpenGL not rendering

[ Edited ]

What changes did you make to replace QWindow? Can you upload your project?

 

Dumi.

New Developer
Posts: 19
Registered: ‎02-24-2012
My Device: Developer
My Carrier: -

Re: Qt and OpenGL not rendering

Hi,

 

I've just tried the cube project without any changes and it works in the simulator. The only thing is that I'm compiling without QT_BOOTSTRAPPED in order to work on my Mac.

Dumi.

Developer
Posts: 133
Registered: ‎03-28-2011
My Device: BlackBerry 9900 & PlayBook
My Carrier: Bell

Re: Qt and OpenGL not rendering

I'm not sure what you did to get it to work, but it definitely didn't work for me.

 

I was thinking of another example, it wasn't QWindow that I had to modify. Anyway, the only modifications that I made were to add a blackberry-tablet.xml file, and the following line in main.cpp :

 

    QCoreApplication::addLibraryPath("app/native/lib");

Without that line, the app would load and instantly close on my device.

 

I figured out through a bunch of tinkering that the issue boils down to the texture. The QImage loads fine, as I can get its dimensions. However, the line glEnable(GL_TEXTURE_2D); in the initTextures() function returns an invalid enum glError, since GL_TEXTURE_2D is invalid in OpenGL ES 2.0. Subsequent calls continue without issue, but there just isn't a texture. We end up with a black cube on a black background. If you change the background, you can see the cube and that it rotates just fine. But I can't figure out why it's not finding the texture.




Founder of Pulsecode Inc. and taab
Authomator - Two-factor authentication codes on BlackBerry 10 - http://www.xitijpatel.com/ - Follow @xitijpatel
Is there a helpful or useful post in this thread? Click the thumbs up on it so that other people can find it more easily!
New Developer
Posts: 19
Registered: ‎02-24-2012
My Device: Developer
My Carrier: -

Re: Qt and OpenGL not rendering

The simulator uses  OpenGL ES 1.1, not 2.0. But Qt is compiled for device with 2.0, while the cube sample application, from what I see, is for 1.1. This is an excerpt from the configure-qsk used by Qt:

 

# Use GLES1 for simulator and GLES2 for device
# TODO: Remove this when simulator supports GLES2
if [ "CPU" == "x86" ]; then
  GL_VERSION="es1"
  echo "Using OpenGL ES 1.0"
else
  GL_VERSION="es2"
  echo "Using OpenGL ES 2.0"
fi

 

Dumi.

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Qt and OpenGL not rendering

You should see something in the log file. To see the log file, you need to be running an unsigned version of the app on your tablet, and SSH in. Then go to /accounts/1000/appdata/youappfolderhere. The log file will be under logs/log in that folder.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
New Developer
Posts: 19
Registered: ‎02-24-2012
My Device: Developer
My Carrier: -

Re: Qt and OpenGL not rendering

If GL_INVALID_ENUM is generated after calling glEnable(GL_TEXTURE_2D) then it's pretty clear that an invalid call is made (1.0/1.1 on 2.0).

 

Dumi.

Developer
Posts: 133
Registered: ‎03-28-2011
My Device: BlackBerry 9900 & PlayBook
My Carrier: Bell

Re: Qt and OpenGL not rendering

Turns out that this was an OpenGL ES 2.0 issue related to the texture repeating. Namely:

 

// Wrap texture coordinates by repeating
    // f.ex. texture coordinate (1.1, 1.2) is same as (0.1, 0.2)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

 

Is not allowed. GL_REPEAT cannot be used with NPOT (Non-Power Of Two) textures in OpenGL ES 2.0. Instead, you have to either clamp to edge, or implement it in your fragment shader.

 

// Wrap texture coordinates by repeating
    // f.ex. texture coordinate (1.1, 1.2) is same as (0.1, 0.2)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

 

Works great now, EXCEPT, when the app starts, it starts with a blank area where the OpenGL is rendered. Once the user taps it, it draws perfectly. No idea why this is the case.


Founder of Pulsecode Inc. and taab
Authomator - Two-factor authentication codes on BlackBerry 10 - http://www.xitijpatel.com/ - Follow @xitijpatel
Is there a helpful or useful post in this thread? Click the thumbs up on it so that other people can find it more easily!
New Developer
Posts: 19
Registered: ‎02-24-2012
My Device: Developer
My Carrier: -

Re: Qt and OpenGL not rendering


HorizonXP wrote:

 

Works great now, EXCEPT, when the app starts, it starts with a blank area where the OpenGL is rendered. Once the user taps it, it draws perfectly. No idea why this is the case.


This happens because there is no update requested for the widget (no glDraw call is made) before the user taps the screen. If you change the timerEvent method to something like below (not optimal, just for testing) you will see the cube from the beginning. At least this happens in my case, on the simulator.

 

void MainWidget::timerEvent(QTimerEvent *e)
{
    Q_UNUSED(e);

    // Decrease angular speed (friction)
    angularSpeed *= 0.99;

    // Stop rotation when speed goes below threshold
    if (angularSpeed < 0.01)
        angularSpeed = 0.0;
    else {
        // Update rotation
        rotation = QQuaternion::fromAxisAndAngle(rotationAxis, angularSpeed) * rotation;
        // Update scene
        // updateGL(); <-- out
    }
    updateGL(); // <-- in
}

 

 

Dumi.

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

Re: Qt and OpenGL not rendering

For all who works with Qt and SImulator, there is an error here

# Use GLES1 for simulator and GLES2 for device
# TODO: Remove this when simulator supports GLES2
if [ "CPU" == "x86" ]; then
  GL_VERSION="es1"
  echo "Using OpenGL ES 1.0"
else
  GL_VERSION="es2"
  echo "Using OpenGL ES 2.0"
fi

 

should be:

# Use GLES1 for simulator and GLES2 for device
# TODO: Remove this when simulator supports GLES2
if [ $CPU == "x86" ]; then
  GL_VERSION="es1"
  echo "Using OpenGL ES 1.0"
else
  GL_VERSION="es2"
  echo "Using OpenGL ES 2.0"
fi

 It does matter when you compile Qt libraries.