#! import sys from OpenGL.GLUT import * from OpenGL.GLU import * from OpenGL.GL import * def setup(): print "Setup" glClearColor(0.8, 0.7, 0.6, 0.0) def display(): print "Display" glClear(GL_COLOR_BUFFER_BIT) glFlush() def reshape(w, h): print "Reshape", w, h glViewport(0, 0, w, h) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() def timer(id): print "Timer", id glutTimerFunc(2000, timer, id) def entry(state): if state == GLUT_LEFT: print "Mouse leaving" else: print "Mouse entering" def motion(x, y): # only generates mouse move when key is down print "Mouse Move", x, y def mouse(button, state, x, y): if state == GLUT_DOWN: state = "down" else: state = "up" if button == GLUT_LEFT_BUTTON: print "Left", state, x, y elif button == GLUT_MIDDLE_BUTTON: print "Middle", state, x, y elif button == GLUT_RIGHT_BUTTON: print "Right", state, x, y def joystick(button, x, y, z): print "Joystick", button, x, y, z keystate = [0] * 256 def modifykey(key): modifier = glutGetModifiers() if modifier: if modifier & GLUT_ACTIVE_CTRL: key = "[CTRL] " + key if modifier & GLUT_ACTIVE_ALT: key = "[ALT] " + key if modifier & GLUT_ACTIVE_SHIFT: key = "[SHIFT] " + key return key def keydown(key, x, y): keystate[ord(key)] = GLUT_DOWN print ord(key), modifykey(key), GLUT_DOWN def keyup(key, x, y): keystate[ord(key)] = GLUT_UP; print ord(key), modifykey(key), GLUT_UP def special(key, x, y): print "Special", key, x, y # Register mouse input callback functions glutInit(sys.argv) glutInitDisplayMode(GLUT_RGBA) glutInitWindowSize(500, 500) glutInitWindowPosition(-1, -1) glutCreateWindow('Input') setup() glutDisplayFunc(display) glutReshapeFunc(reshape) # Keyboard glutSpecialFunc( special ) glutKeyboardFunc( keydown ) glutKeyboardUpFunc( keyup ) # Mouse glutEntryFunc(entry) glutMouseFunc(mouse) glutMotionFunc(motion) # Timer glutTimerFunc(2000, timer, 1) # Joystick glutJoystickFunc( joystick, 500 ) glutMainLoop()