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

I work since more than 20 years as a developer, product manager and AI lead with language technologies. Starting with speech recognition and machine translation I now focus on education in semantic technologies and LLMs.

Check out my AI trainings.

Contact me and book your training.

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

pbouda@outlook.com
+351 917403181
Lisbon, Portugal