Esempio n. 1
0
 def window_visibility_handler(self, state):
     if state != GLUT.GLUT_VISIBLE:
         return
     GLUT.glutSetWindow(self.window)
     with Subject._threadlock:
         GrContext._full_init = True
     GLUT.glutVisibilityFunc(None)
Esempio n. 2
0
    def gl_init(self):
        # sys.stderr.write("Starting GLUTContext.gl_init\n")
        if self is not GLUTContext._default_instance:
            # sys.stderr.write("Making a GLUT window.\n")
            GLUT.glutInitWindowSize(self._width, self._height)
            GLUT.glutInitWindowPosition(0, 0)
            self.window = GLUT.glutCreateWindow(
                bytes(self._title, encoding="UTF-8"))
        GLUT.glutSetWindow(self.window)
        GLUT.glutMouseFunc(lambda button, state, x, y: self.
                           mouse_button_handler(button, state, x, y))
        GLUT.glutReshapeFunc(
            lambda width, height: self.resize2d(width, height))
        GLUT.glutDisplayFunc(lambda: self.draw())
        GLUT.glutVisibilityFunc(
            lambda state: self.window_visibility_handler(state))
        # Right now, the timer just prints FPS
        GLUT.glutTimerFunc(0, lambda val: self.timer(val), 0)
        GLUT.glutCloseFunc(lambda: self.cleanup())

        for coltype in object_collection.GLObjectCollection.collection_classes:
            self.object_collections.append(
                object_collection.GLObjectCollection.
                collection_classes[coltype](self))
        # self.object_collections.append(object_collection.SimpleObjectCollection(self))
        # self.object_collections.append(object_collection.CurveCollection(self))

        self.window_is_initialized = True
        GLUTContext._instances.append(self)
Esempio n. 3
0
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()
Esempio n. 4
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)
Esempio n. 5
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)
Esempio n. 6
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
Esempio n. 7
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)
Esempio n. 8
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)