def main(): GLUT.glutInit(sys.argv) GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH) GLUT.glutInitWindowSize(320, 240) global window window = GLUT.glutCreateWindow("Babal") GLUT.glutDisplayFunc(display_cb) GLUT.glutVisibilityFunc(visibility_cb) GLUT.glutReshapeFunc(reshape_cb) GLUT.glutIgnoreKeyRepeat(1) GLUT.glutKeyboardFunc(keyboard_cb) GLUT.glutKeyboardUpFunc(keyboard_up_cb) GLUT.glutSpecialFunc(special_cb) GLUT.glutSpecialUpFunc(special_up_cb) GLUT.glutJoystickFunc(joystick_cb, 0) map_file = None if len(sys.argv) > 1: map_file = open(sys.argv[1]) global game game = Game(map_file) gl_draw.init(GL, GLU, game) # reshape_cb gets called when window is made visible GLUT.glutMainLoop()
def __init__( self, width=256, height=256, title=None, visible=True, aspect=None, decoration=True, fullscreen=False, config=None, context=None, color=(0,0,0,1), vsync=False): if vsync: log.warn('vsync not implemented for osxglut backend') if len(__windows__) > 0: log.critical( """OSXGLUT backend is unstable with more than one window.\n""" """Exiting...""") sys.exit(0) window.Window.__init__(self, width=width, height=height, title=title, visible=visible, aspect=aspect, decoration=decoration, fullscreen=fullscreen, config=config, context=context, color=color) if config is None: config = configuration.Configuration() set_configuration(config) self._native_window = glut.glutCreateWindow( self._title ) if bool(glut.glutSetOption): glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE, glut.GLUT_ACTION_CONTINUE_EXECUTION) glut.glutSetOption(glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS, glut.GLUT_ACTION_CONTINUE_EXECUTION) glut.glutWMCloseFunc( self._close ) glut.glutDisplayFunc( self._display ) glut.glutReshapeFunc( self._reshape ) glut.glutKeyboardFunc( self._keyboard ) glut.glutKeyboardUpFunc( self._keyboard_up ) glut.glutMouseFunc( self._mouse ) glut.glutMotionFunc( self._motion ) glut.glutPassiveMotionFunc( self._passive_motion ) glut.glutVisibilityFunc( self._visibility ) glut.glutEntryFunc( self._entry ) glut.glutSpecialFunc( self._special ) glut.glutSpecialUpFunc( self._special_up ) glut.glutReshapeWindow( self._width, self._height ) if visible: glut.glutShowWindow() else: glut.glutHideWindow() # This ensures glutCheckLoop never blocks def on_idle(): pass glut.glutIdleFunc(on_idle) __windows__.append(self)
def __init__(self, width=256, height=256, title=None, visible=True, decoration=True, fullscreen=False, config=None, context=None): if len(__windows__) > 0: log.critical( """OSXGLUT backend is unstable with more than one window.\n""" """Exiting...""") sys.exit(0) window.Window.__init__(self, width, height, title, visible, decoration, fullscreen, config, context) if config is None: config = configuration.Configuration() set_configuration(config) self._native_window = glut.glutCreateWindow(self._title) if bool(glut.glutSetOption): glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE, glut.GLUT_ACTION_CONTINUE_EXECUTION) glut.glutSetOption(glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS, glut.GLUT_ACTION_CONTINUE_EXECUTION) glut.glutWMCloseFunc(self._close) glut.glutDisplayFunc(self._display) glut.glutReshapeFunc(self._reshape) glut.glutKeyboardFunc(self._keyboard) glut.glutKeyboardUpFunc(self._keyboard_up) glut.glutMouseFunc(self._mouse) glut.glutMotionFunc(self._motion) glut.glutPassiveMotionFunc(self._passive_motion) glut.glutVisibilityFunc(self._visibility) glut.glutEntryFunc(self._entry) glut.glutSpecialFunc(self._special) glut.glutSpecialUpFunc(self._special_up) glut.glutReshapeWindow(self._width, self._height) if visible: glut.glutShowWindow() else: glut.glutHideWindow() # This ensures glutCheckLoop never blocks def on_idle(): pass glut.glutIdleFunc(on_idle) __windows__.append(self)
def attachGLUT(self): glut.glutMouseFunc(self.mouseInputHandler) glut.glutMouseWheelFunc(self.mouseWheelHandler) glut.glutMotionFunc(self.mouseMoveHandler) glut.glutPassiveMotionFunc(self.mouseMoveHandler) glut.glutKeyboardFunc(self.keyboardHandler) glut.glutKeyboardUpFunc(lambda *x:self.keyboardHandler(*x,isEnd=True)) glut.glutSpecialFunc(self.specialKeyHandler) glut.glutSpecialUpFunc(lambda *x:self.specialKeyHandler(*x,isEnd=True))
def attachGLUT(self): glut.glutMouseFunc(self.mouseInputHandler) glut.glutMouseWheelFunc(self.mouseWheelHandler) glut.glutMotionFunc(self.mouseMoveHandler) glut.glutPassiveMotionFunc(self.mouseMoveHandler) glut.glutKeyboardFunc(self.keyboardHandler) glut.glutKeyboardUpFunc( lambda *x: self.keyboardHandler(*x, isEnd=True)) glut.glutSpecialFunc(self.specialKeyHandler) glut.glutSpecialUpFunc( lambda *x: self.specialKeyHandler(*x, isEnd=True))
def __init__(self, width=None, height=None, caption=None, visible=True, fullscreen=False): event.EventDispatcher.__init__(self) self._event_queue = [] if width and width > 0: self._width = width else: self._width = Window._default_width if height and height > 0: self._height = height else: self._height = Window._default_height if caption is None: caption = sys.argv[0] self._caption = caption self._saved_width = self._width self._saved_height = self._height if _window is None: glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH) self._window_id = glut.glutCreateWindow(self._caption) glut.glutDisplayFunc(self._display) glut.glutReshapeFunc(self._reshape) glut.glutKeyboardFunc(self._keyboard) glut.glutKeyboardUpFunc(self._keyboard_up) glut.glutMouseFunc(self._mouse) glut.glutMotionFunc(self._motion) glut.glutPassiveMotionFunc(self._passive_motion) glut.glutVisibilityFunc(self._visibility) glut.glutEntryFunc(self._entry) glut.glutSpecialFunc(self._special) glut.glutSpecialUpFunc(self._special_up) gl.glClearColor(0,0,0,0) self._visible = visible self._time = glut.glutGet(glut.GLUT_ELAPSED_TIME) if not visible: glut.glutHideWindow() else: glut.glutShowWindow() self.set_size(self._width, self._height) screen_width = glut.glutGet(glut.GLUT_SCREEN_WIDTH) screen_height= glut.glutGet(glut.GLUT_SCREEN_HEIGHT) glut.glutPositionWindow((screen_width-self._width)//2, (screen_height-self._height)//2) self.fullscreen = fullscreen
def main(self): """Main function responsible for run the game.""" glut.glutInit(sys.argv) # Select type of Display mode: # Double buffer # RGBA color # Alpha components supported # Depth buffer glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DOUBLE | glut.GLUT_DEPTH) # get a 640 x 480 window glut.glutInitWindowSize(1000, 800) # the window starts at the upper left corner of the screen glut.glutInitWindowPosition(0, 0) # Asign name of the window glut.glutCreateWindow("PacMan") # Register the function called when the keyboard is pressed. glut.glutKeyboardFunc(self.key_pressed) glut.glutSpecialFunc(self.key_pressed_special) glut.glutSpecialUpFunc(self.key_pressed_special_up) # Register the drawing function with glut. glut.glutDisplayFunc(self.draw_scene) # Uncomment this line to get full screen. # glut.glutFullScreen() # When we are doing nothing, redraw the scene. glut.glutIdleFunc(self.draw_scene) # Register the function called when our window is resized. glut.glutReshapeFunc(self.re_size_gl_scene) # Initialize our window. self.init_gl(640, 480) # Start Event Processing Engine glut.glutMainLoop()
def __init__(self, scene): """Sets up the core functionality we need to begin rendering. This includes the OpenGL configuration, the window, the viewport, the event handler and update loop registration. """ super(Application, self).__init__(scene) if self.scene.core_profile: raise ValueError("GLUT does not support Core profile") # glut initialization GLUT.glutInit(sys.argv) GLUT.glutInitDisplayMode(GLUT.GLUT_DOUBLE | GLUT.GLUT_RGBA | GLUT.GLUT_DEPTH) # set the window's dimensions GLUT.glutInitWindowSize(1024, 768) # set the window caption # create our window GLUT.glutCreateWindow("PyGLy - GLUT - " + scene.name) # print some opengl information pygly.gl.print_gl_info() # create the scene now that we've got our window open self.scene.initialise() self.last_time = time() # set the function to draw GLUT.glutReshapeFunc(self.on_window_resized) GLUT.glutIdleFunc(self.idle) GLUT.glutDisplayFunc(self.render) GLUT.glutKeyboardFunc(self.on_key_pressed) GLUT.glutKeyboardUpFunc(self.on_key_released) GLUT.glutSpecialFunc(self.on_special_key_pressed) GLUT.glutSpecialUpFunc(self.on_special_key_released)
def __init__( self, scene ): """Sets up the core functionality we need to begin rendering. This includes the OpenGL configuration, the window, the viewport, the event handler and update loop registration. """ super( Application, self ).__init__( scene ) if self.scene.core_profile: raise ValueError( "GLUT does not support Core profile" ) # glut initialization GLUT.glutInit( sys.argv ) GLUT.glutInitDisplayMode( GLUT.GLUT_DOUBLE | GLUT.GLUT_RGBA | GLUT.GLUT_DEPTH ) # set the window's dimensions GLUT.glutInitWindowSize( 1024, 768 ) # set the window caption # create our window GLUT.glutCreateWindow( "PyGLy - GLUT - " + scene.name ) # print some opengl information pygly.gl.print_gl_info() # create the scene now that we've got our window open self.scene.initialise() self.last_time = time() # set the function to draw GLUT.glutReshapeFunc( self.on_window_resized ) GLUT.glutIdleFunc( self.idle ) GLUT.glutDisplayFunc( self.render ) GLUT.glutKeyboardFunc( self.on_key_pressed ) GLUT.glutKeyboardUpFunc( self.on_key_released ) GLUT.glutSpecialFunc( self.on_special_key_pressed ) GLUT.glutSpecialUpFunc( self.on_special_key_released )
global deltaMove if key == glut.GLUT_KEY_UP: deltaMove = 0.5 elif key == glut.GLUT_KEY_DOWN: deltaMove = -0.5 # ------------------------------------------------------- def releaseKey(key, xx, yy): global deltaMove deltaMove = 0 # ------------------------------------------------------- # main program init glut.glutInit() glut.glutInitWindowSize(800, 600) glut.glutInitDisplayMode(glut.GLUT_RGB | glut.GLUT_DOUBLE | glut.GLUT_DEPTH) glut.glutCreateWindow("DynSimTest") glut.glutDisplayFunc(render) glut.glutIdleFunc(simulate) glut.glutMouseFunc(mouseButton) glut.glutMotionFunc(mouseMove) glut.glutSpecialFunc(pressKey) glut.glutSpecialUpFunc(releaseKey) init() glut.glutMainLoop()
def __init__(self, size=None, position=None, title=None, fullscreen=False,enableAlpha=True,pointSize=2): ''' Constructor ''' self._mouse_x = 0 self._mouse_y = 0 self._button = mouse.NONE self._modifiers = None self._motionEventCounter=0 self._time = None self._timer_stack = [] self._timer_date = [] self._title = title or "PyGLer" # FIXME: get default name from a central location self._fullscreen = -1 self.dragSensitivity = 5 # Is there any glut loop already running ? if glut.glutGetWindow( ) == 0: glut.glutInit() glut.glutInitDisplayMode( glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH ) self._interactive = False else: self._interactive = True self._id = glut.glutCreateWindow( self._title ) glut.glutShowWindow() glut.glutDisplayFunc( self.redraw ) glut.glutReshapeFunc( self._reshape ) glut.glutKeyboardFunc( self._keyboard ) glut.glutKeyboardUpFunc( self._keyboard_up ) glut.glutMouseFunc( self._mouse ) glut.glutMotionFunc( self._motion ) glut.glutPassiveMotionFunc( self._passive_motion ) glut.glutVisibilityFunc( self._visibility ) glut.glutEntryFunc( self._entry ) glut.glutSpecialFunc( self._special ) glut.glutSpecialUpFunc( self._special_up ) GL.glEnable(GL.GL_DEPTH_TEST) GL.glEnable(GL.GL_BLEND) if enableAlpha: GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); GL.glPolygonOffset(1, 1); GL.glEnable(GL.GL_POLYGON_OFFSET_FILL); GL.glPointSize(pointSize) GL.glEnable(GL.GL_PROGRAM_POINT_SIZE) if size is not None: width, height = size glut.glutReshapeWindow( width, height ) width = glut.glutGet( glut.GLUT_WINDOW_WIDTH ) height= glut.glutGet( glut.GLUT_WINDOW_HEIGHT ) self._width = width self._height = height if position is not None: x,y = position glut.glutPositionWindow( x, y ) x = glut.glutGet( glut.GLUT_WINDOW_X ) y = glut.glutGet( glut.GLUT_WINDOW_X ) self._x, self._y = x, y # These ones will be used when exiting fullscreen self._saved_width = self._width self._saved_height = self._height self._saved_x = self._x self._saved_y = self._y self._time = glut.glutGet( glut.GLUT_ELAPSED_TIME ) self._fullscreen = fullscreen if fullscreen: self.set_fullscreen(True)
def start(self): GLUT.glutIgnoreKeyRepeat(True) GLUT.glutSpecialFunc(self.special_keyboard_down) GLUT.glutSpecialUpFunc(self.special_keyboard_up)
def __init__( self, size=None, position=None, title=None, fullscreen=False): ''' Create a window with given sise, position and title. :param (int,int) size: Initial window size as (width,height) in pixels. :param (int,int) position: Initial window position. Depending on the window-manager, the position request may or may not be honored. :param string title: The title of the window. ''' global _window window.Window.__init__( self, size, position, title ) self._mouse_x = 0 self._mouse_y = 0 self._button = mouse.NONE self._modifiers = None self._time = None self._timer_stack = [] self._timer_date = [] self._title = title or sys.argv[0] self._fullscreen = -1 # Is there any glut loop already running ? if glut.glutGetWindow( ) == 0: glut.glutInit( sys.argv ) glut.glutInitDisplayMode( glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH ) self._interactive = False else: self._interactive = True self._id = glut.glutCreateWindow( self._title ) glut.glutShowWindow( ) glut.glutDisplayFunc( self._display ) glut.glutReshapeFunc( self._reshape ) glut.glutKeyboardFunc( self._keyboard ) glut.glutKeyboardUpFunc( self._keyboard_up ) glut.glutMouseFunc( self._mouse ) glut.glutMotionFunc( self._motion ) glut.glutPassiveMotionFunc( self._passive_motion ) glut.glutVisibilityFunc( self._visibility ) glut.glutEntryFunc( self._entry ) glut.glutSpecialFunc( self._special ) glut.glutSpecialUpFunc( self._special_up ) if size is not None: width, height = size glut.glutReshapeWindow( width, height ) width = glut.glutGet( glut.GLUT_WINDOW_WIDTH ) height= glut.glutGet( glut.GLUT_WINDOW_HEIGHT ) self._width = width self._height = height if position is not None: x,y = position glut.glutPositionWindow( x, y ) #else: # screen_width = glut.glutGet( glut.GLUT_SCREEN_WIDTH ) # screen_height= glut.glutGet( glut.GLUT_SCREEN_HEIGHT ) # x = (screen_width - self._size[0]) / 2 # y = (screen_width - self._size[0]) / 2 # glut.glutPositionWindow( x, y ) x = glut.glutGet( glut.GLUT_WINDOW_X ) y = glut.glutGet( glut.GLUT_WINDOW_X ) self._x, self._y = x, y # These ones will be used when exiting fullscreen self._saved_width = self._width self._saved_height = self._height self._saved_x = self._x self._saved_y = self._y self._time = glut.glutGet( glut.GLUT_ELAPSED_TIME ) _window = self self._fullscreen = False if fullscreen: self.set_fullscreen(True)