Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. OpenGL calls with beforeRendering() and afterRendering() : sample code ?
Qt 6.12 LTS is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 1 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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);
    glRectf(-0.5f,0.5f,0.5f,-0.5f);

    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 ?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      The code with glOrtho I tried to make sure I render on top of the qml :
      glDisable(GL_DEPTH_TEST);
      glMatrixMode(GL_PROJECTION);
      glPushMatrix();
      glLoadIdentity();
      glOrthof(0, width(), 0, height(), -5, 1);
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();

      Still no progress on my side...

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Just found exactly what I want here :
        http://qt-project.org/doc/qt-5.0/qtgui/openglwindow.html

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

        @
        if(!m_device)
        m_device = new QOpenGLPaintDevice;
        m_device->setSize(size());

        QPainter painter(m_device);
        painter.setPen(Qt::blue);
        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt
        • Unsolved