示例#1
0
 def _vispy_set_visible(self, visible):
     # Show or hide the window or widget
     glut.glutSetWindow(self._id)
     if visible:
         glut.glutShowWindow()
     else:
         glut.glutHideWindow()
示例#2
0
 def _vispy_set_visible(self, visible):
     # Show or hide the window or widget
     glut.glutSetWindow(self._id)
     if visible:
         glut.glutShowWindow()
     else:
         glut.glutHideWindow()
示例#3
0
def main():
    global EVENT_MNGR, EVENT_DISP, EVENT_LIST,\
            PROJECTION_MTRX, LOOKAT_MTRX, ASPECT_RATIO
    atexit.register(on_exit)
    glut.glutInit(sys.argv)
    OpenGL.GLUT.freeglut.glutSetOption(OpenGL.GLUT.GLUT_ACTION_ON_WINDOW_CLOSE, OpenGL.GLUT.GLUT_ACTION_GLUTMAINLOOP_RETURNS)
    init_window()
    EVENT_DISP = GloveletSensorEventDispatcher('/dev/ttyACM0', 115200)
    EVENT_LIST = GloveletDemoController()
    EVENT_MNGR = EventDispatchManager(EVENT_DISP, EVENT_LIST)
    init_hand()
    glut.glutShowWindow()
    # Init shaders
    if not init_shaders():
        print('Failed to compile and link shader program.')
    # init OpenGL settings
    gl.glEnable(gl.GL_TEXTURE_2D)
    gl.glEnable(gl.GL_DEPTH_TEST)
    # set render callback
    glut.glutDisplayFunc(draw)
    glut.glutKeyboardFunc(keyboard_handler)
    # glut.glutPassiveMotionFunc(mouse_motion)
    # init perspective matrices
    PROJECTION_MTRX = glm.perspective(glm.radians(45.0), ASPECT_RATIO, 0.1, 100.0)
    LOOKAT_MTRX = glm.lookAt(glm.vec3((0.0, 2.0, -4.0), dtype='f'),  # eye
                             glm.vec3((0.0, 1.0, 0.0), dtype='f'),  # center
                             glm.vec3((0.0, 1.0, 0.0), dtype='f'))  # up
    # begin main loop
    EVENT_MNGR.deploy_dispatchers()
    glut.glutMainLoop()
    EVENT_MNGR.end_dispatchers()
    exit()
示例#4
0
    def show(self):
        '''
        The show() method causes a window to be displayed as soon as possible.
        '''

        glut.glutSetWindow( self._id )
        glut.glutShowWindow()
        self.dispatch_event('on_show')
示例#5
0
    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)
示例#6
0
    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)
示例#7
0
    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
示例#8
0
 def show(self):
     self.activate()
     glut.glutShowWindow()
     self.dispatch_event('on_show')
示例#9
0
 def show(self):
     self.activate()
     glut.glutShowWindow()
     self.dispatch_event("on_show")
示例#10
0
    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)
示例#11
0
    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)