03-03-2012 04:03 AM
I've implemented the example in the Qt 4.8 SDK under opengl/cube.
http://qt.gitorious.org/qt/qt/trees/4.8/examples/o
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?
Solved! Go to Solution.
03-03-2012 05:52 AM - edited 03-03-2012 05:52 AM
What changes did you make to replace QWindow? Can you upload your project?
Dumi.
03-03-2012 06:45 AM
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.
03-03-2012 07:45 AM
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.
03-03-2012 08:20 AM
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.
03-03-2012 09:33 AM
03-03-2012 02:40 PM
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.
03-03-2012 05:40 PM
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.
03-04-2012 02:01 AM
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.
03-05-2012 10:14 AM
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.