如果我运行这段代码
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from OpenGL.GLUT.freeglut import *
def on_wheel(wheel, direction, x, y):
print(wheel, direction, x, y)
glutInit()
glutInitWindowSize(100, 100)
glutCreateWindow("glutMouseWheelFunc test")
glutMouseWheelFunc( on_wheel ) # Error here
glutMainLoop()
我收到此错误
Traceback (most recent call last):
File "...", line 28, in <module>
glutMouseWheelFunc( on_wheel )
File ".../OpenGL/GLUT/special.py", line 148, in __call__
self.wrappedOperation( cCallback, *args )
File ".../OpenGL/GLUT/special.py", line 116, in failFunction
typeName, 'glut%sFunc'%(typeName),
OpenGL.error.NullFunctionError: Undefined GLUT callback function MouseWheel,
check for bool(glutMouseWheelFunc) before calling
这是Windows的解决方案:
How to use FreeGLUT glutMouseWheelFunc in PyOpenGL program?
但是如何在Mac或Linux上的pyopengl中调用 glutMouseWheelFunc()
?
或者更好:是否有便携式解决方案?
答案 0 :(得分:0)
函数 glutMouseFunc()应该在 glutMouseWheelFunc()之前定义,该示例现在可以在Linux上通过以下代码在您的代码中使用:
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from OpenGL.GLUT.freeglut import *
def mouse(button, state, x, y):
print(button, state, x, y)
def on_wheel(wheel, direction, x, y):
print(wheel, direction, x, y)
glutInit()
glutInitWindowSize(100, 100)
glutCreateWindow("glutMouseWheelFunc test")
glutMouseFunc( mouse )
glutMouseWheelFunc( on_wheel )
glutMainLoop()