OpenGL calls with beforeRendering() and afterRendering() : sample code ?

  • Hi,

    Actually I'm an openGL newbie. I'm trying to tweak the openglunderqml example to change the openGL calls at QQuickWindow::beforeRendering() and QQuickWindow::afterRendering() since I need to diplay something in front of a qml app. I don't want to use a shader but draw a simple box using "classic" opengl functions in Squircle::paint() :
    glViewport(0,0,window->width(), window->height());
    glColor3f(1.0f, 0.0f, 0.0f);

    What I don't understand is :

    • Why the box is flashing like hell when called beforeRendering(), and disappears when the window is resized
    • Why is the box simply not there when called form afterRendering() ? I tried to use glOrtho to make sure it is visible, with no success.

    Il'll also need to achieve text rendering there using opengl, however it is not in the context of a QGlWidget and no renderText() is available. Would there be a way to do it using Qt, for example with a QGLWidget created with the same context as the QtQuick Scene Graph ?

  • The code with glOrtho I tried to make sure I render on top of the qml :
    glOrthof(0, width(), 0, height(), -5, 1);

    Still no progress on my side...

  • Just found exactly what I want here :

    A QPainter with QOpenGLPaintDevice can paint on the OpenGL context in beforeRendering or afterRendering :

    m_device = new QOpenGLPaintDevice;

    QPainter painter(m_device);
    painter.drawText(QRect(0,0,width(),height()), Qt::TextDontClip, "Hello World");

    However I still don't know why bare opengl instructions don't work as expected ! I'm actually exploring what the QOpenGLPaintDevice does using the glintercept tool.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.