Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt and OpenGL using QGLWidget

Qt and OpenGL using QGLWidget

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 4.3k Views
  • 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.
  • L Offline
    L Offline
    lbolduc
    wrote on 28 Nov 2013, 16:09 last edited by
    #1

    I am planning on porting our 3D editor for our engine from a MFC sdi application to a Qt application. What i have done so far is very basic but i am having issues.

    I have a QMainWindow with a few docking widgets. For the central widget i have subclassed QGLWidget and overridden the 3 methods initializeGL, resizeGL and painGL. What i'm doing so far in these methods is very basic :

    @/////////////////////////////////////////////////////////////////////////////////////////
    /// One time initialization.
    void SceneView::initializeGL()
    {
    glEnable(GL_DEPTH_TEST);
    glClearColor(0.25f, 0.25f, 0.25f, 1.0f);
    }

    /////////////////////////////////////////////////////////////////////////////////////////
    /// Called when the widget is resized.
    void SceneView::resizeGL(int w, int h)
    {
    // Setup viewport, projection etc.
    glViewport(0, 0, (GLint)w, (GLint)h);
    }

    /////////////////////////////////////////////////////////////////////////////////////////
    /// Called when the widget is redrawn.
    void SceneView::paintGL()
    {
    glClear(GL_COLOR_BUFFER_BIT);
    }@

    The problem is when i resize the application or one of the docking window, there is flickering. If i remove docking windows, there is still eavy flickering. It's like the gl widget is not redrawing at the same time as the rest. If i replace the gl widget by a stadard widget like QTextEdit, there is no problem.

    I am using Qt 5.1.1 OpenGL with VS2012 toolchain.

    We think in gereralities but we live in details

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 29 Nov 2013, 09:05 last edited by
      #2

      QGLWidget class is deprecated. If you are writing new code, you should use QOpenGL* set of classes instead (and Qt 5.2, where the GL stuff has seen lots of updates).

      (Z(:^

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on 29 Nov 2013, 09:35 last edited by
        #3

        @sierdzio When you want to use whole window new QWindow with an OpenGL surface format is the way to go but I don't think there is a replacement for QGLWidget. Or is embedding QWindow with QWidget::createWindowContainer() the new recommendation for widget-based apps?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 29 Nov 2013, 09:43 last edited by
          #4

          I don't know, sorry. I'm just repeating the general impression I get from following the dev mailing list, and posts on this forum made by ZapB, who is the maintainer of OpenGL stuff in Qt.

          (Z(:^

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on 29 Nov 2013, 09:51 last edited by
            #5

            I will answer myself: "Introducing QWidget::createWindowContainer()":http://blog.qt.digia.com/blog/2013/02/19/introducing-qwidgetcreatewindowcontainer/
            Looks like that's the way.
            @lbolduc try to replace QGLWidget with QWindow and see if that fixes the problem.

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lbolduc
              wrote on 30 Nov 2013, 22:53 last edited by
              #6

              Thanks for the answers.

              @Chris Kawa : yes i have read this post and i have tried to make a QWindow derived widget and to wrap it with createWindowContainer. It works (3D rendering works) but it has the same problem as the QGLWidget i.e. it causes flickering when the application is resized or when a docking widget in the application is resized (or as soon as some part of the application like a menu gets over the gl widget).

              I have also read an older post about native widgets and how Qt 4.4 was supposed to address this problem
              "Your text to link here...":http://blog.qt.digia.com/blog/2007/08/09/qt-invaded-by-aliens-the-end-of-all-flicker/

              Unfortunatly, it seems the problem isn't solve with OpenGL widgets. I know Qt 5.2 is supposed to have updates concerning OpenGL, is this problem supposed to be solved with Qt 5.2 ?

              We think in gereralities but we live in details

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on 1 Dec 2013, 10:31 last edited by
                #7

                Hm, you might try another approach. Flickering is caused by rapid repaints while resizing. You can try to "pause" the painting in OpenGL area when the resizing starts and refresh only when it's done.

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lbolduc
                  wrote on 1 Dec 2013, 12:02 last edited by
                  #8

                  Yes, or it is caused by erasing the background when repainting. There are various flags to control this behavior like Qt::WA_OpaquePaintEvent. I have tried those flags but it didn't change anything. I have also tried setting autoFillBackground to false but it didn't change anything either.

                  Btw, is it possible for me to upload the source code of my little program, it might be easier for someone more experienced then me with Qt to see what the problem is.

                  We think in gereralities but we live in details

                  1 Reply Last reply
                  0

                  1/8

                  28 Nov 2013, 16:09

                  • Login

                  • Login or register to search.
                  1 out of 8
                  • First post
                    1/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved