Revisiting PyQt and OpenGL

It’s been I while since I used OpenGL with PyQt, for example in my live coding experiments with GLSL shaders. Those were still done with PyQt4 and the good old QGLWidget. In Qt5 the preferred way to render in OpenGL canvases is to use the new QOpenGL* classes. Those have the advantage that they provide a full collection of OpenGL drawing functions, so it is not necessary to import any external OpenGL library (like PyOpenGL) anymore. The disadvantage is that there is currently no convenient way to create and initialize such a window with a nice render function, as was provided by the QGLWidget.

I finally collected some code from the PyQt5 OpenGL examples and with some modification I was able to run it (from the snapshot of PyQt5 on Github). Their class OpenGLWindow provides what you need for the first steps, you can just subclass it and add your code to your own render() function. I added some more interesting shaders from here, et voilĂ  le chocolat:

https://github.com/pbouda/stuff/blob/master/opengl/pyqt/chocolux.py

Time to connect this with some live coding…

About me

My name is Peter Bouda and I am a software developer with more than 20 years of professional experience in application development. I help you to bring your application to market as quickly as possible.

Read about my work
or
Contact me

Send me a message and I will get back to you.


RSS Feed