Nominate our 2022 Qt Champions!

[SOLVED] OpenGL ES 2.0 and QML working example for Nokia N9

  • Hi all,

    I have started making a game in OpenGL for Nokia N9; I got something going with OpenGL using QGLWidget and the OpenGL ES 2.0 samples from the Qt SDK (textures2, cube and hellogl_es2). The problem now is that I want to add some decent looking UI and doing this only in OpenGL ES 2.0 is a REAL PAIN. So I want to do my UI using QML and keep the game in OpenGL;
    I have seen this question answered a lot of times on different forums, and it looks like it's possible, the idea being to use a QDeclarativeItem, override its paint() method and put the code from QGLWidget::paintGL() and use QPainter::begin/endNativePainting()
    @QDeclarativeView *view = new QDeclarativeView;
    QGLWidget *glWidget = new QGLWidget;

    It's kind of working but the custom QML OpenGL item (QDeclarativeItem derived) is drawing all over the screen, even though in main.qml I specifically tell it to have a width and height of only 200;

    I tried various things, but nothing works, my custom OGL QML item is full screen :( ...

    Seeing that OpenGL is now such an important app feature in post iPhone mobile world why doesn't Nokia provide such an example? Is there anywhere in the corners of the internet a simple WORKING example of integrating OpenGL ES 2.0 with QML (that ideally works on N9)?

    Thanks & regards,

  • Is this (non-fullscreen OpenGL ES 2 QML item) even possible on Nokia N9? Now that I think about it, the other posts that said it was possible were referring to OpenGL 1.x for Windows target (like "here": ).

    I guess I will start to do my UI QWidget based. "This": is a good example of implementing an info button inside a QGLWidget. But I would just HATE it, after months of working on this UI, to find out that I could have done it easily in a few days just by using QML (together with animations etc).

  • I solved it by doing it the other way around: instead of starting with a QDeclarativeView with main.qml and then trying to stuff the custom opengl QDeclarativeItem inside it, I started with a QWidget, where I put the custom QGLWidget together with QDeclarativeView s that host my UI, something like below (where Window is derived from QWidget):

    @#include "window.h"

    #include <QDeclarativeView>

    #include "glwidget.h"

    QHBoxLayout* hBox = new QHBoxLayout(this);

    QSizePolicy fixedSizePolicy;
    QDeclarativeView* qmlLeftTBar = new QDeclarativeView(this);
    QSize qmlTBarsize(80, 480);
    glWidget = new GLWidget(0, 0);
    QDeclarativeView* qmlRightTBar = new QDeclarativeView(this);


    The only downside is that by using QWidget root UI it is not as easy to support portrait orientation on N9.

Log in to reply