def create_window(self, params): if self.__glut_window is None: # init GLUT ! pymt_logger.debug('WinGlut: GLUT initialization') glutInit('') glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH | GLUT_MULTISAMPLE | GLUT_STENCIL | GLUT_ACCUM) # create the window self.__glut_window = glutCreateWindow('pymt') # register all callbcaks glutReshapeFunc(self._glut_reshape) glutMouseFunc(self._glut_mouse) glutMotionFunc(self._glut_mouse_motion) glutKeyboardFunc(self._glut_keyboard) # update window size glutShowWindow() self.size = params['width'], params['height'] if params['fullscreen']: pymt_logger.debug('WinGlut: Set window to fullscreen mode') glutFullScreen() super(MTWindowGlut, self).create_window(params)
def create_window(self, params): if self.__glut_window is None: # init GLUT ! pymt_logger.debug('WinGlut: GLUT initialization') glutInit('') if 'PYMT_GLUT_UNITTEST' in os.environ: glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE) else: glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH | GLUT_MULTISAMPLE | GLUT_STENCIL | GLUT_ACCUM) # create the window self.__glut_window = glutCreateWindow('pymt') # register all callbcaks glutReshapeFunc(self._glut_reshape) glutMouseFunc(self._glut_mouse) glutMotionFunc(self._glut_mouse_motion) glutKeyboardFunc(self._glut_keyboard) # update window size glutShowWindow() self.size = params['width'], params['height'] if params['fullscreen']: pymt_logger.debug('WinGlut: Set window to fullscreen mode') glutFullScreen() super(MTWindowGlut, self).create_window(params)
def register(self): """ register callbacks with glut """ glutMouseFunc(self.handle_mouse_button) glutMotionFunc(self.handle_mouse_move) glutKeyboardFunc(self.handle_keystroke) glutSpecialFunc(self.handle_keystroke) glutPassiveMotionFunc(None)
def register(self): """ 注册glut的事件回调函数 """ glutMouseFunc(self.handle_mouse_button) glutMotionFunc(self.handle_mouse_move) glutKeyboardFunc(self.handle_keystroke) glutSpecialFunc(self.handle_keystroke)
def register(self): print('进入register函数') """ 注册glut的事件回调函数 """ glutMouseFunc(self.handle_mouse_button) glutMotionFunc(self.handle_mouse_move) glutKeyboardFunc(self.handle_keystroke) print('尝试过调用self.handle_keystroke()函数') glutSpecialFunc(self.handle_keystroke) print('尝试第二次')
def main(path=None): glutInit(sys.argv) if sys.platform == 'darwin': if not path: path = dialog() if not path: sys.exit(0) glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE) glutInitWindowPosition(0, 0) glutInitWindowSize(730, 650) win = glutCreateWindow(b'MIDI Player') (width, height, img) = read_image(join(dirname(__file__), 'mixer.ppm')) glPixelStorei(GL_UNPACK_ALIGNMENT, 1) texture = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, texture) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, img) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glMatrixMode(GL_TEXTURE) glLoadIdentity() glScale(1 / width, 1 / height, 1) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0, 730, 0, 650, 0, 1) player = Player(win, path, width, height) glutDisplayFunc(player.display_func) glutKeyboardFunc(player.keyboard_func) glutMouseFunc(player.mouse_func) glutMotionFunc(player.motion_func) glutIdleFunc(player.process_events) submenus = [] for instrument in range(128): if instrument % 8 == 0: submenus.append([ families[instrument // 8], glutCreateMenu(player.change_instrument) ]) glutAddMenuEntry(instruments[instrument].encode('ascii'), instrument) glutCreateMenu(player.change_instrument) for family, submenu in submenus: glutAddSubMenu(family.encode('ascii'), submenu) glutAttachMenu(GLUT_RIGHT_BUTTON) glutMainLoop()
def main(path=None): glutInit(sys.argv) if sys.platform == 'darwin': if not path: path = dialog() if not path: sys.exit(0) glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE) glutInitWindowPosition(0, 0) glutInitWindowSize(730, 650) win = glutCreateWindow(b'MIDI Player') (width, height, img) = read_image('mixer.ppm') glPixelStorei(GL_UNPACK_ALIGNMENT, 1) rbo = c_uint(int(glGenRenderbuffersEXT(1))) glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rbo) glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, width, height) fbo = c_uint(int(glGenFramebuffersEXT(1))) glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, fbo) glFramebufferRenderbufferEXT(GL_READ_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, rbo) glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fbo) glClear(GL_COLOR_BUFFER_BIT) glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, img) glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0) player = Player(win, path, width, height) glutDisplayFunc(player.display_func) glutKeyboardFunc(player.keyboard_func) glutMouseFunc(player.mouse_func) glutMotionFunc(player.motion_func) glutIdleFunc(player.process_events) submenus = [] for instrument in range(128): if instrument % 8 == 0: submenus.append([families[instrument // 8], glutCreateMenu(player.change_instrument)]) glutAddMenuEntry(instruments[instrument].encode('ascii'), instrument) glutCreateMenu(player.change_instrument) for family, submenu in submenus: glutAddSubMenu(family.encode('ascii'), submenu) glutAttachMenu(GLUT_RIGHT_BUTTON) glutMainLoop()
def main(path=None): glutInit(sys.argv) if sys.platform == 'darwin': if not path: path = dialog() if not path: sys.exit(0) glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE) glutInitWindowPosition(0, 0) glutInitWindowSize(730, 650) win = glutCreateWindow(b'MIDI Player') (width, height, img) = read_image(join(dirname(__file__), 'mixer.ppm')) glPixelStorei(GL_UNPACK_ALIGNMENT, 1) texture = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, texture) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, img) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glMatrixMode(GL_TEXTURE) glLoadIdentity() glScale(1/width, 1/height, 1) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0, 730, 0, 650, 0, 1) player = Player(win, path, width, height) glutDisplayFunc(player.display_func) glutKeyboardFunc(player.keyboard_func) glutMouseFunc(player.mouse_func) glutMotionFunc(player.motion_func) glutIdleFunc(player.process_events) submenus = [] for instrument in range(128): if instrument % 8 == 0: submenus.append([families[instrument // 8], glutCreateMenu(player.change_instrument)]) glutAddMenuEntry(instruments[instrument].encode('ascii'), instrument) glutCreateMenu(player.change_instrument) for family, submenu in submenus: glutAddSubMenu(family.encode('ascii'), submenu) glutAttachMenu(GLUT_RIGHT_BUTTON) glutMainLoop()
def init_opengl(self, width, height, x, y): glutInit() glutInitWindowPosition(x, y) glutInitWindowSize(width, height) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_MULTISAMPLE) glutCreateWindow("Rainbow Alga") glutDisplayFunc(self.render) glutIdleFunc(self.render) glutReshapeFunc(self.resize) glutMouseFunc(self.mouse) glutMotionFunc(self.drag) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.special_keyboard) glClearDepth(1.0) glClearColor(0.0, 0.0, 0.0, 0.0) glMatrixMode(GL_PROJECTION) glLoadIdentity() glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 3000) glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT) # Lighting light_ambient = (0.0, 0.0, 0.0, 1.0) light_diffuse = (1.0, 1.0, 1.0, 1.0) light_specular = (1.0, 1.0, 1.0, 1.0) light_position = (-100.0, 100.0, 100.0, 0.0) mat_ambient = (0.7, 0.7, 0.7, 1.0) mat_diffuse = (0.8, 0.8, 0.8, 1.0) mat_specular = (1.0, 1.0, 1.0, 1.0) high_shininess = (100) glEnable(GL_LIGHT0) glEnable(GL_NORMALIZE) glEnable(GL_COLOR_MATERIAL) glEnable(GL_LIGHTING) glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient) glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse) glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular) glLightfv(GL_LIGHT0, GL_POSITION, light_position) glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient) glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse) glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular) glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess) # Transparency glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
def run(): global window glutInit(sys.argv) # Select type of Display mode: # Double buffer # RGBA color # Alpha components supported # Depth buffer glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) # get a 640 x 480 window resolution = get_state()["camera"]["resolution"] glutInitWindowSize(int(resolution[0]), int(resolution[1])) # the window starts at the upper left corner of the screen glutInitWindowPosition(0, 0) # Okay, like the C version we retain the window id to use when closing, but for those of you new # to Python (like myself), remember this assignment would make the variable local and not global # if it weren't for the global declaration at the start of main. window = glutCreateWindow("Waffle") # Register the drawing function with glut, BUT in Python land, at least using PyOpenGL, we need to # set the function pointer and invoke a function to actually register the callback, otherwise it # would be very much like the C version of the code. glutDisplayFunc(DrawGLScene) # Uncomment this line to get full screen. # glutFullScreen() # When we are doing nothing, redraw the scene. glutIdleFunc(idleFunc) # Register the function called when our window is resized. glutReshapeFunc(ReSizeGLScene) # Register the function called when the keyboard is pressed. glutKeyboardFunc(keyDown) glutKeyboardUpFunc(keyUp) glutMouseFunc(onMouseClick) glutMotionFunc(onMouseClickMove) glutPassiveMotionFunc(onMouseMove) # Initialize our window. InitGL() init_world() init_interface() # Start Event Processing Engine glutMainLoop()
def initialize(self): """Sets up the OpenGL window and binds input callbacks to it """ glutKeyboardFunc(self._on_key_down) glutSpecialFunc(self._on_special_key_down) # [Keyboard/Special]Up methods aren't supported on some old GLUT implementations has_keyboard_up = False has_special_up = False try: if bool(glutKeyboardUpFunc): glutKeyboardUpFunc(self._on_key_up) has_keyboard_up = True if bool(glutSpecialUpFunc): glutSpecialUpFunc(self._on_special_key_up) has_special_up = True except NullFunctionError: # Methods aren't available on this GLUT version pass if not has_keyboard_up or not has_special_up: # Warn on old GLUT implementations that don't implement much of the interface. self._logger.warning( "Warning: Old GLUT implementation detected - keyboard remote control of Vector disabled." "We recommend installing freeglut. %s", _glut_install_instructions()) self._is_keyboard_control_enabled = False else: self._is_keyboard_control_enabled = True try: GLUT_BITMAP_9_BY_15 except NameError: self._logger.warning( "Warning: GLUT font not detected. Help message will be unavailable." ) glutMouseFunc(self._on_mouse_button) glutMotionFunc(self._on_mouse_move) glutPassiveMotionFunc(self._on_mouse_move) glutIdleFunc(self._idle) glutVisibilityFunc(self._visible)
def activate(self, width, height): glutInit(['mesh_viewer']) glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH) glutInitWindowSize(width, height) glutInitWindowPosition(0, 0) self.root_window_id = glutCreateWindow(self.titlebar) glutDisplayFunc(self.on_draw) glutTimerFunc(100, self.checkQueue, 0) glutReshapeFunc(self.on_resize_window) glutKeyboardFunc(self.on_keypress) glutMouseFunc(self.on_click) glutMotionFunc(self.on_drag) # for r, lst in enumerate(self.mesh_viewers): # for c, mv in enumerate(lst): # mv.glut_window_id = glutCreateSubWindow(self.root_window_id, c*width/len(lst), r*height/len(self.mesh_viewers), width/len(lst), height/len(self.mesh_viewers)) glutDisplayFunc(self.on_draw) self.init_opengl() glutMainLoop() # won't return until process is killed
def register_callbacks(): """ Registers the following callbacks with GLUT: - glutKeyboardFunc - glutKeyboardUpFunc - glutSpecialFunc - glutSpecialUpFunc - glutMotionFunc - glutPassiveMotionFunc - glutMouseFunc """ glutKeyboardFunc(_key_down) glutKeyboardUpFunc(_key_up) glutSpecialFunc(_special_down) glutSpecialUpFunc(_special_up) glutMotionFunc(_mouse_pos_listener) glutPassiveMotionFunc(_mouse_pos_listener) glutMouseFunc(_mouse_button_listener)
def register(self): """ to rigister glut's event-callback-function""" glutMouseFunc(self.handle_mouse_button) glutMotionFunc(self.handle_mouse_move) glutKeyboardFunc(self.handle_keystroke) glutSpecialFunc(self.handle_keystroke)