Используя glutMouseWheelFunc из FreeGLUT в PyOpenGL? - PullRequest
0 голосов
/ 09 октября 2018

Если я запускаю этот код

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:

Как использовать FreeGLUT glutMouseWheelFuncв программе PyOpenGL?

Но как мне вызвать glutMouseWheelFunc() в pyopengl на Mac или Linux?

Или лучше: есть ли переносимое решение?

1 Ответ

0 голосов
/ 12 июня 2019

Функция 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()
...