问题
I have installed PyOpenGL from here for 64-bit Python 3.x and Windows 7. I am able to write and execute a PyOpenGL program that uses glutMouseFunc to listen to mouse button clicks:
from OpenGL.GLUT import *
from OpenGL.GL import *
# Imagine the typical glut init functions here ...
glutMouseFunc( mouse )
Now, I want to read the scroll wheel of the mouse too. I have done this before in C++ using FreeGLUT, which exposes a glutMouseWheelFunc. I checked and I can see freeglut32.vc9.dll and freeglut64.vc9.dll in C:\Program Files\Python32\Lib\site-packages\OpenGL\DLLS
.
I changed the above code to:
from OpenGL.GLUT import *
from OpenGL.GLUT.freeglut import *
from OpenGL.GL import *
# Imagine the typical glut init functions here ...
glutMouseFunc( mouse )
glutMouseWheelFunc( mouseWheel )
This fails with this error:
File "c:\Program Files\Python32\lib\site-packages\OpenGL\GLUT\special.py", line 139, in __call__
self.wrappedOperation( cCallback, *args )
File "c:\Program Files\Python32\lib\site-packages\OpenGL\GLUT\special.py", line 107, in failFunction
typeName, 'glut%sFunc'%(typeName),
OpenGL.error.NullFunctionError: Undefined GLUT callback function MouseWheel, check for bool(glutMouseWheelFunc) before calling
So, how do I use FreeGLUT calls in PyOpenGL? What I am doing wrong?
回答1:
PyOpenGL loads the GLUT dll by default. To use freeglut instead, rename or delete the glut64.vc9.dll file in the OpenGL/DLLs directory and make sure no such file exists elsewhere in the Windows DLL search path. Works for me.
来源:https://stackoverflow.com/questions/10359407/how-to-use-freeglut-glutmousewheelfunc-in-pyopengl-program