Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Using FreeGLUT calls with PyOpenGL

📅 2012-Apr-28 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ freeglut, glut, pyopengl, python ⬩ 📚 Archive

PyOpenGL exposes OpenGL GL, GLU and GLUT calls to Python programs. The FreeGLUT library was developed as an extension to GLUT and adds some important functionality to GLUT. The one which I like the most is the support for the scroll wheel of the mouse.

To use GLUT calls in a Python program, we do:

from OpenGL.GLUT import *

However, it is not obvious how to use the FreeGLUT functionality from PyOpenGL. If I include a FreeGLUT call like glutMouseWheelFunc() in a Python program, it crashes with an error:

OpenGL.error.NullFunctionError: Undefined GLUT callback function MouseWheel, check for bool(glutMouseWheelFunc) before calling

On further investigation, it turns out that PyOpenGL chooses the first available DLL between glut and freeglut. This can be seen in Python32\Lib\site-packages\OpenGL\platform\ So, to get FreeGLUT functionality, we need to make PyOpenGL to pick the freeglut DLL file instead of glut. We can do this by deleting the glut DLL file(s) in Python32\Lib\site-packages\OpenGL\DLLS. Once this is done, PyOpenGL should pick the freeglut DLL and the FreeGLUT calls should be routed to it without any problem.

Tried with: PyOpenGL 3.0.2a6 and Python 3.2 64-bit

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧