def __init__(self, width: int, height: int, title: str, camera: bool = False): self.__Daytime = True self.__enableCamera = camera glut.glutInit() glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA) glut.glutInitWindowSize(width, height) glut.glutInitWindowPosition(0, 0) glut.glutCreateWindow(title) glut.glutReshapeFunc(self.__window_resize) glut.glutDisplayFunc(self.__display) glut.glutKeyboardFunc(self.__keyboardDown) glut.glutKeyboardUpFunc(self.__keyboardUp) glut.glutMotionFunc(self.__mouse_look_clb) self._create_shader() self.setSky(True) glEnable(GL_DEPTH_TEST) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) self.__ElementsList = [] self.__camera = Camera() self.__lastX = width / 2 self.__lastY = height / 2 self.__first_mouse = True self.__left = False self.__right = False self.__forward = False self.__backward = False
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, *args, **kwargs): BaseCanvasBackend.__init__(self) title, size, show, position = self._process_backend_kwargs(kwargs) glut.glutInitWindowSize(size[0], size[1]) self._id = glut.glutCreateWindow(title.encode('ASCII')) if not self._id: raise RuntimeError('could not create window') glut.glutSetWindow(self._id) _VP_GLUT_ALL_WINDOWS.append(self) # Cache of modifiers so we can send modifiers along with mouse motion self._modifiers_cache = () self._closed = False # Keep track whether the widget is closed # Register callbacks glut.glutDisplayFunc(self.on_draw) glut.glutReshapeFunc(self.on_resize) # glut.glutVisibilityFunc(self.on_show) glut.glutKeyboardFunc(self.on_key_press) glut.glutSpecialFunc(self.on_key_press) glut.glutKeyboardUpFunc(self.on_key_release) glut.glutMouseFunc(self.on_mouse_action) glut.glutMotionFunc(self.on_mouse_motion) glut.glutPassiveMotionFunc(self.on_mouse_motion) _set_close_fun(self._id, self.on_close) self._vispy_canvas_ = None if position is not None: self._vispy_set_position(*position) if not show: glut.glutHideWindow()
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 __init__(self, *args, **kwargs): BaseCanvasBackend.__init__(self, *args) title, size, position, show, vsync, resize, dec, fs, parent, context, \ = self._process_backend_kwargs(kwargs) self._initialized = False # Deal with context if not context.istaken: context.take('glut', self) _set_config(context.config) else: raise RuntimeError('Glut cannot share contexts.') glut.glutInitWindowSize(size[0], size[1]) self._id = glut.glutCreateWindow(title.encode('ASCII')) if not self._id: raise RuntimeError('could not create window') glut.glutSetWindow(self._id) _VP_GLUT_ALL_WINDOWS.append(self) if fs is not False: self._fullscreen = True self._old_size = size if fs is not True: logger.warning('Cannot specify monitor for glut fullscreen, ' 'using default') glut.glutFullScreen() else: self._fullscreen = False # Cache of modifiers so we can send modifiers along with mouse motion self._modifiers_cache = () self._closed = False # Keep track whether the widget is closed # Register callbacks glut.glutDisplayFunc(self.on_draw) glut.glutReshapeFunc(self.on_resize) # glut.glutVisibilityFunc(self.on_show) glut.glutKeyboardFunc(self.on_key_press) glut.glutSpecialFunc(self.on_key_press) glut.glutKeyboardUpFunc(self.on_key_release) glut.glutMouseFunc(self.on_mouse_action) glut.glutMotionFunc(self.on_mouse_motion) glut.glutPassiveMotionFunc(self.on_mouse_motion) _set_close_fun(self._id, self.on_close) if position is not None: self._vispy_set_position(*position) if not show: glut.glutHideWindow() # Init self._initialized = True self._vispy_set_current() self._vispy_canvas.events.initialize()
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, neuronObject, displaysize=(800, 600), radius=5, poly=True, fast=False, multisample=True, graph=True): self.poly = poly self.displaysize = displaysize self.graph = graph title = 'btmorph OpenGL Viewer' GLUT.glutInit(sys.argv) if multisample: GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE) else: GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_MULTISAMPLE) GLUT.glutInitWindowSize(self.displaysize[0], self.displaysize[1]) GLUT.glutInitWindowPosition(50, 50) GLUT.glutCreateWindow(title) GLUT.glutDisplayFunc(self.display) GLUT.glutReshapeFunc(self.reshape) GLUT.glutMouseFunc(self.mouse) GLUT.glutMotionFunc(self.mouseMove) GLUT.glutMouseWheelFunc(self.mouseWheel) GLUT.glutKeyboardFunc(self.keyDown) GLUT.glutKeyboardUpFunc(self.keyUp) mb = modelbuilder() self.root, self.vertices_gl, self.colors_gl, self.Neuron = \ mb.build(neuronObject, self.poly, 100, fast) if graph: self.gb = graphbuilder() self.Graph, mid = \ self.gb.build(neuronObject, scalefactor=100) self.initGL(multisample) self.camera.rad = radius self.camera.focus = mid while self.running: GLUT.glutMainLoopEvent() GLUT.glutDestroyWindow(GLUT.glutGetWindow())
def __init__(self, name='glut window', *args, **kwargs): BaseCanvasBackend.__init__(self) self._id = glut.glutCreateWindow(name) global ALL_WINDOWS ALL_WINDOWS.append(self) # Cache of modifiers so we can send modifiers along with mouse motion self._modifiers_cache = () # Note: this seems to cause the canvas to ignore calls to show() # about half of the time. # glut.glutHideWindow() # Start hidden, like the other backends # Register callbacks glut.glutDisplayFunc(self.on_draw) glut.glutReshapeFunc(self.on_resize) # glut.glutVisibilityFunc(self.on_show) glut.glutKeyboardFunc(self.on_key_press) glut.glutSpecialFunc(self.on_key_press) glut.glutKeyboardUpFunc(self.on_key_release) glut.glutMouseFunc(self.on_mouse_action) glut.glutMotionFunc(self.on_mouse_motion) glut.glutPassiveMotionFunc(self.on_mouse_motion) # Set close function. See issue #10. For some reason, the function # can still not exist even if we checked its boolean status. closeFuncSet = False if bool(glut.glutWMCloseFunc): # OSX specific test try: glut.glutWMCloseFunc(self.on_close) closeFuncSet = True except OpenGL.error.NullFunctionError: pass if not closeFuncSet: try: glut.glutCloseFunc(self.on_close) closeFuncSet = True except OpenGL.error.NullFunctionError: pass # glut.glutFunc(self.on_) self._initialized = False # LC: I think initializing here makes it more consistent with other # backends glut.glutTimerFunc(0, self._emit_initialize, None)
def run(self): glut.glutInit() glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DOUBLE | glut.GLUT_ALPHA | glut.GLUT_DEPTH) glut.glutInitWindowSize(self.window_width, self.window_height) self.window = glut.glutCreateWindow("Point cloud test") glut.glutDisplayFunc(self.display_base) glut.glutIdleFunc(self.display_base) glut.glutReshapeFunc(self.resize_event) glut.glutKeyboardFunc(self.keyboard_press_event) glut.glutKeyboardUpFunc(self.keyboard_up_event) glut.glutMouseFunc(self.mouse_button_event) glut.glutMotionFunc(self.mouse_moved_event) self.init_gl(self.window_width, self.window_height) glut.glutMainLoop()
def __init__(self, cam_model_files, tracked_cam_parameters, cam_track, point_cloud): point_cloud_ids, point_cloud_points, point_cloud_colors = point_cloud if point_cloud_colors is None: point_cloud_colors = np.ones(point_cloud_points.shape, dtype=np.float32) point_cloud_scale = _detect_point_cloud_scale(point_cloud_points) point_cloud_target_scale = 3 point_cloud_points = _rescale_point_cloud( point_cloud_points, point_cloud_target_scale / point_cloud_scale) cam_track = _rescale_track( cam_track, point_cloud_target_scale / point_cloud_scale) self._tracked_cam_track_len = len(cam_track) self._tracked_cam_track_pos_float = 0.0 self._camera = recordclass('CameraPoseAndParameters', 'yaw pitch pos fov_y')( 0.0, 0.0, np.array([0, 0, 10.0]), self._camera_fov_y_range.default) GLUT.glutInit() GLUT.glutInitWindowSize(600, 400) GLUT.glutInitWindowPosition(0, 0) self._data = recordclass('AnimationData', 'prev_time key_states last_xy')( GLUT.glutGet(GLUT.GLUT_ELAPSED_TIME), np.array([False] * 256), None) GLUT.glutCreateWindow(b'Camera track renderer') GLUT.glutDisplayFunc(self.display) GLUT.glutKeyboardFunc(self.key_pressed) GLUT.glutKeyboardUpFunc(self.key_up) GLUT.glutIdleFunc(self.animate) GLUT.glutMouseFunc(self.mouse_event) GLUT.glutMotionFunc(self.mouse_move) self._renderer_impl = CameraTrackRenderer( cam_model_files, tracked_cam_parameters, cam_track, PointCloud(point_cloud_ids, point_cloud_points, point_cloud_colors))
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 )
def run(self, _width=None, _height=None, _show_window=True): # Init glut self._show_window = _show_window GLUT.glutInit(()) GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_ALPHA | GLUT.GLUT_DEPTH) if _width is not None and _height is not None: GLUT.glutInitWindowSize(_width, _height) #self.resizeGL(_width, _height) # this line crashes my program ?? else: GLUT.glutInitWindowSize(*self.window_size) GLUT.glutInitWindowPosition(0, 0) self.window = GLUT.glutCreateWindow(self.title) if not _show_window: GLUT.glutHideWindow() GLUT.glutDisplayFunc(self.drawGL) GLUT.glutReshapeFunc(self.resizeGL) GLUT.glutKeyboardFunc(self.mykeyboard) GLUT.glutKeyboardUpFunc(self.mykeyboardup) GLUT.glutMouseFunc(self.mouseFunc) GLUT.glutMotionFunc(self.motionFunc) self.initGL(*self.window_size)
def __init__(self, **kwargs): BaseCanvasBackend.__init__(self, capability, SharedContext) title, size, position, show, vsync, resize, dec, fs, context = \ self._process_backend_kwargs(kwargs) _set_config(context) glut.glutInitWindowSize(size[0], size[1]) self._id = glut.glutCreateWindow(title.encode('ASCII')) if not self._id: raise RuntimeError('could not create window') glut.glutSetWindow(self._id) _VP_GLUT_ALL_WINDOWS.append(self) if fs is not False: if isinstance(fs, int): logger.warn('Cannot specify monitor for glut fullscreen, ' 'using default') glut.glutFullScreen() # Cache of modifiers so we can send modifiers along with mouse motion self._modifiers_cache = () self._closed = False # Keep track whether the widget is closed # Register callbacks glut.glutDisplayFunc(self.on_draw) glut.glutReshapeFunc(self.on_resize) # glut.glutVisibilityFunc(self.on_show) glut.glutKeyboardFunc(self.on_key_press) glut.glutSpecialFunc(self.on_key_press) glut.glutKeyboardUpFunc(self.on_key_release) glut.glutMouseFunc(self.on_mouse_action) glut.glutMotionFunc(self.on_mouse_motion) glut.glutPassiveMotionFunc(self.on_mouse_motion) _set_close_fun(self._id, self.on_close) self._vispy_canvas_ = None if position is not None: self._vispy_set_position(*position) if not show: glut.glutHideWindow()
enemies.append(Ship()) initWindowWidth = 1200 # unit: pixels initWindowHeight = 1000 # unit: pixels Element.screen_width = initWindowWidth Element.screen_height = initWindowHeight initWindowPosition_X = 100 # unit: pixels initWindowPosition_Y = 100 # unit: pixels GLUT.glutInit(sys.argv) # Caracterisation de la fenetre d'affichage GLUT.glutInitDisplayMode(GLUT.GLUT_DOUBLE | GLUT.GLUT_RGBA | GLUT.GLUT_DEPTH) # Taille de la fenetre de rendu GLUT.glutInitWindowSize(initWindowWidth, initWindowHeight) # Position de la fenetre GLUT.glutInitWindowPosition(initWindowPosition_X, initWindowPosition_Y) # creation de la fenetre GLUT.glutCreateWindow('BE OpenGL Supelec') # appel de la fonction d'initialisation init() # declaration des fonctions GLUT : GLUT.glutDisplayFunc(display) GLUT.glutReshapeFunc(reshape) GLUT.glutKeyboardFunc(keyboard) GLUT.glutKeyboardUpFunc(keyboard_up) # Boucle infinie d'interaction GLUT.glutMainLoop()
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)
# enables the user to change the position of the camera via keyboard input def handle_special_keypress(key, x, y): if key == GLUT_KEY_LEFT and not camera.position.x == 24: camera.position += glm.vec3(10.0, 0.0, 0.0) if key == GLUT_KEY_RIGHT and not camera.position.x == -26: camera.position -= glm.vec3(10.0, 0.0, 0.0) if key == GLUT_KEY_UP and not camera.position.y == 60: camera.position += glm.vec3(0.0, 10.0, 0.0) if key == GLUT_KEY_DOWN and not camera.position.y == 0: camera.position -= glm.vec3(0.0, 10.0, 0.0) glut.glutKeyboardUpFunc(keyboard_up_input) glut.glutSpecialFunc(handle_special_keypress) def keyboard_input(key, x, y): pressed_keys.add(key) if key == b'-': player.scale -= glm.vec3(0.1) player.scaling(player.scale) if key == b'+': player.scale += glm.vec3(0.1) player.scaling(player.scale) if key == b'r':
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)