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 https://github.com/flux242/qtzpk.git
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.
4 comments:
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. :)
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!!
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.
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.
Post a Comment