Question

I have some code using Qt 4. I want to migrate it to Qt 5 and switch to QOpenGL stuff. I can't understand where the code from void paintGL() and void initializeGL() needs to go in a QWindow. Can anyone help me with an example?

Was it helpful?

Solution

I have created a simple example of using QWindow with OpenGL.

To simplify OpenGL development I have created an abstract class GLWindow, which contains the virtual functions initializeGL(), paintGL() and resizeGL(int w, int h). I believe the source code shows the relationship between the old style and the new style.

The example is available here:

https://github.com/mortennobel/QtOpenGLChapter/tree/master/OpenGL3xAlt

OTHER TIPS

Qt has at least one example (Overpainting) of putting widgets over an OpenGL scene. By looking at that, it appears the easiest way would be to inherit from QGLWidget instead of QWidget and override the appropriate virtual functions for initialize and paint.

The standard example for using QWindow with OpenGL is hellowindow in qtbase/examples/opengl.

There is no direct replacement for initializeGL and paintGL. Instead you do something like this:

  • Have a QWindow with surface type OpenGLSurface.
  • Create a QOpenGLContext with a matching format.
  • When the window receives an expose event, start rendering (makeCurrent, your GL calls and finally swapBuffers).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top