|
A Python code block using it looks the same as the equivalent C/C++. Where you would pass GLUT a C callback function, you can pass a callable PyObject to PyGLUT. Most simply, that would be a normal Python function, but it typically would be a wrapped function of another compiled extension that uses OpenGL internally.
def display():
# Call some extension that renders using OpenGL.
# ...
glutSwapBuffers()
def mouse(button, state, x, y):
if state == GLUT_UP: ...
if state == GLUT_DOWN: ...
def motion(x, y):
...
def keyboard(key, x, y):
...
def menu_func(event):
print 'Menu entry', event, 'selected'
glutInit(1, ['poop'])
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE)
win_id = glutCreateWindow('PyGLUT')
glutDisplayFunc(display)
glutMotionFunc(motion)
glutKeyboardFunc(keyboard)
glutMouseFunc(mouse)
menu = glutCreateMenu(menu_func)
glutAddMenuEntry("Menu entry 1", 1)
glutAddMenuEntry("Menu entry 2", 2)
glutMainLoop()
In the zip you will find the source code and a compiled Win32 dll Python extension. Also in the zip are a custom build of the Python 1.5.2 interpreter, a custom built Glut32.dll, the Python shell exe and a simple demo script.
To run the demo on Win32, simply unzip the download and double-click on RUN.bat.