Monday, July 22, 2013

OpenGL Core Profile and an overlay with the QPainter

I've played recently with the OpenGL Core Profile and QGLWidget to see if I can render a scene with only core profile functions and shaders. Everything worked well until I decided to add an FPS counter using overlaid text drawn with the QPainter.

In short - it is not possible to use QPainter with the Core Profile. To create such overlays the QGLWidget context should work in Compatibility Mode otherwise application crashes. Additionally all core objects including VBO's shall be properly unbinded in each paint before calling QPainter functions. It really took time for me to understand why my application crashes.

I've uploaded my QT application to the github. It's an example of how to use QGLWidget with shaders and QPainter to lay something over a scene rendered using OpenGL.

To get the code:
git clone
To compile and start it QT Creator can be used. Open project file with the QT Creator and press Ctrl-R. At least QT 5.0 is required.


Anonymous said...

Thank you very much for your post and for uploading it to github!! I was having trouble interleaving opengl and qpainter and taking your example solved my problems. :)

Anonymous said...

Thank you so much for this post and your code on github!! I was struggling with the openGL / QPainter problem the entire day, leaving me really frustrated. Your code made my error clear and therefore it also made my day!!

Photo-realistic Rendering said...

Thanks for the cool application! I was wondering how to pull out the grammar of L-system from the source. Some hint would be helpful.

Wild Bill said...

Could not get it to work out of the box on Mac using OpenGL 2.1; had shader compile errors. When fixed shaders to version 120, compiled without errors, but still wouldn't render the OpenGL.

Author should update this example to use QOpenGLWindow. The example looks very worthwhile.