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:

Time to connect this with some live coding…

About me

My name is Peter Bouda and I am and Angular/JavaScript coach and consultant with more than 15 years of professional experience in web application development. I help you to bring your web product to market as quickly as possible.

Read about my work
Contact me

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