Guglie
Guglie

Reputation: 2441

Using glutMouseWheelFunc from FreeGLUT in PyOpenGL?

If I run this code

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

I get this error

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

Here's the solution for Windows:

How to use FreeGLUT glutMouseWheelFunc in PyOpenGL program?

But how can I call glutMouseWheelFunc() in pyopengl on Mac or linux?

Or better: is there a portable solution?

Upvotes: 1

Views: 670

Answers (1)

Stan S.
Stan S.

Reputation: 277

The function glutMouseFunc() should be defined before glutMouseWheelFunc() the example now works from your code with the following on 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()

Upvotes: 1

Related Questions