【问题标题】:Using glutMouseWheelFunc from FreeGLUT in PyOpenGL?在 PyOpenGL 中使用来自 FreeGLUT 的 glutMouseWheelFunc?
【发布时间】:2019-03-14 09:01:55
【问题描述】:

如果我运行这段代码

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()

或者更好:有便携式解决方案吗?

【问题讨论】:

    标签: python glut freeglut pyopengl


    【解决方案1】:

    应该在 glutMouseWheelFunc() 之前定义函数 glutMouseFunc() 该示例现在可以在您的代码中运行,在 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()
    

    【讨论】:

    • 谢谢,不幸的是,这给出了 OpenGL.error.NullFunctionError: Undefined GLUT callback function MouseWheel,在调用之前检查 bool(glutMouseWheelFunc),所以我想它不被支持
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2017-01-22
    相关资源
    最近更新 更多