コード例 #1
0
    def run(self):
        GLUT.glutInit()
        GLUT.glutSetOption(GLUT.GLUT_MULTISAMPLE, 4)
        GLUT.glutInitDisplayMode(GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH
                                 | GLUT.GLUT_MULTISAMPLE)
        self.width = 1200
        self.height = 720

        GLUT.glutInitWindowSize(self.width, self.height)
        GLUT.glutInitWindowPosition(100, 100)

        self.window = GLUT.glutCreateWindow(self.title)

        self.init_program()

        self.clear()
        self.show_loading_screen()
        self.init_line_buffer()
        self.load_line_buffer()

        GLUT.glutDisplayFunc(self.display)
        GLUT.glutIdleFunc(self.idle)
        GLUT.glutReshapeFunc(self.reshape)
        GLUT.glutKeyboardFunc(self.keyboard)
        GLUT.glutSpecialFunc(self.special)
        GLUT.glutMouseFunc(self.mouse)
        GLUT.glutMotionFunc(self.motion)
        GLUT.glutPassiveMotionFunc(self.motion)

        GLUT.glutMainLoop()
コード例 #2
0
ファイル: _glut.py プロジェクト: kif/vispy
    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()
コード例 #3
0
ファイル: backend_osxglut.py プロジェクト: glumpy/glumpy
    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)
コード例 #4
0
ファイル: backend_osxglut.py プロジェクト: rougier/unity
    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)
コード例 #5
0
    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()
コード例 #6
0
ファイル: main.py プロジェクト: jpkell05/hyperdim
def initGLWindow(width, height):
	# init GL window
	GLUT.glutInit(sys.argv)
	GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_ALPHA | GLUT.GLUT_DEPTH)
	GLUT.glutInitWindowSize(width, height)
	GLUT.glutInitWindowPosition(0, 0)
	GLUT.glutCreateWindow("Hyper Dimensions v1.0 (beta)")
	# set callback functions
	GLUT.glutDisplayFunc(drawGLScene)	# rendering function
	GLUT.glutIdleFunc(drawGLScene)		# idle function
	GLUT.glutTimerFunc(10, updateScene, 1);
	GLUT.glutPassiveMotionFunc(mousePassiveMotion)
コード例 #7
0
ファイル: angleGui.py プロジェクト: Nhanbk/robotbuddy
    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))
コード例 #8
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
コード例 #9
0
    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))
コード例 #10
0
ファイル: _glut.py プロジェクト: dengemann/vispy
    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)
コード例 #11
0
    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)
コード例 #12
0
ファイル: viewer_app.py プロジェクト: luchak/radiosity-viewer
  def __init__(
      self,
      update_callback = _EmptyOneArgCallback,
      display_callback = _EmptyZeroArgCallback,
      init_callback = _EmptyZeroArgCallback,
      key_callback = _EmptyThreeArgCallback,
      window_name = 'viewer',
      window_size = (640, 480),
      frame_rate = 60,
      clear_color = (0.0, 0.0, 0.0, 1.0),
      field_of_view = 45.0,
      ):
    self.update_callback = update_callback
    self.display_callback = display_callback
    self.key_callback = key_callback

    self.ms_per_frame = int(1000.0 / frame_rate)
    self.field_of_view = field_of_view

    GLUT.glutInit()
    GLUT.glutInitWindowSize(*window_size)
    GLUT.glutInitDisplayMode(GLUT.GLUT_DOUBLE | GLUT.GLUT_RGB | GLUT.GLUT_DEPTH)
    GLUT.glutCreateWindow(window_name)
    GLUT.glutDisplayFunc(self.Display)
    GLUT.glutKeyboardFunc(self.Key)
    GLUT.glutReshapeFunc(self.Reshape)
    GLUT.glutMouseFunc(self.Mouse)
    GLUT.glutMotionFunc(self.Motion)
    GLUT.glutPassiveMotionFunc(self.PassiveMotion)

    GL.glEnable(GL.GL_DEPTH_TEST)
    GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL)
    GL.glClearColor(*clear_color)
    self.Reshape(*window_size)

    self.camera_theta = 0.0
    self.camera_phi = 0.0
    self.camera_r = 10.0
    self.camera_center = numpy.array((0.0, 0.0, 0.0))
    self.UpdateCameraRotationMatrix()

    self.mouse_drag_mode = None

    init_callback()
コード例 #13
0
ファイル: glutapp.py プロジェクト: eduble/panteda
    def init(self, w=None, h=None):
        if w:   self.width = w
        if h:   self.height = h

        try:
            glut.glutInit()
        except Exception as e:
            print(e)
            sys.exit()

        if pl.system() == 'Darwin': #Darwin: OSX
            glut.glutInitDisplayString('double rgba samples=8 core depth')
        else:   #Other: Linux
            try:
                glut.glutInitDisplayMode(
                        glut.GLUT_DOUBLE | \
                        glut.GLUT_RGBA | \
                        glut.GLUT_MULTISAMPLE | \
                        glut.GLUT_DEPTH)
            except Exception as e:
                print('Issue detected')
                print(e)
                sys.exit()
        glut.glutInitWindowSize (self.width, self.height)
        glut.glutCreateWindow (self.label)

        self.handler.init()

        glut.glutDisplayFunc(self.display)
        glut.glutKeyboardFunc(self.on_key_press)
        glut.glutMouseFunc(self.on_mouse_click)
        glut.glutMotionFunc(self.on_mouse_motion)
        glut.glutPassiveMotionFunc(self.on_mouse_motion)
        glut.glutReshapeFunc(self.on_resize)

        self.last_glut_idle_time = time.time()
        glut.glutIdleFunc(self.on_glut_idle)
        if self.streamed:
            # sakura core defines the main program loop,
            # so we have to run GLUT's own loop in another
            # greenlet.
            self.spawn_greenlet_loop()
コード例 #14
0
ファイル: _glut.py プロジェクト: MatthieuDartiailh/vispy
    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()
コード例 #15
0
ファイル: triangle.py プロジェクト: devforfu/pyogldev
def tiny_glut(args):
    global vertex_code, fragment_code
    scale = 0.01

    def display():
        CAMERA.render()
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        nonlocal scale
        scale_location = gl.glGetUniformLocation(program, "gScale")
        assert scale_location != 0xffffffff
        world_location = gl.glGetUniformLocation(program, "gWorld")
        assert world_location != 0xffffffff

        scale += 0.01

        pipeline = Pipeline(rotation=[0.0, 30*scale, 0.0],
                            # scaling=[math.sin(scale)] * 3,
                            translation=[0, 0, 6],
                            projection=ProjParams(WINDOW_WIDTH, WINDOW_HEIGHT, 1.0, 100.0, 60.0))
        pipeline.set_camera(CAMERA)

        gl.glUniformMatrix4fv(world_location, 1, gl.GL_TRUE, pipeline.get_wvp())
        gl.glDrawElements(gl.GL_TRIANGLES, 18, gl.GL_UNSIGNED_INT, ctypes.c_void_p(0))
        glut.glutSwapBuffers()
        # glut.glutPostRedisplay()

    def mouse(x, y):
        CAMERA.mouse(x, y)

    def keyboard(key, x, y):
        if key == glut.GLUT_KEY_F1:
            sys.exit(0)
        elif key == glut.GLUT_KEY_HOME:
            CAMERA.setup()
        else:
            CAMERA.keyboard(key)

    glut.glutInit(args)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_3_2_CORE_PROFILE)
    glut.glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT)
    glut.glutInitWindowPosition(400, 100)
    # glut.glutCreateWindow("Camera Tutorial")
    glut.glutGameModeString("1920x1200@32")
    glut.glutEnterGameMode()

    # callbacks initialization
    glut.glutDisplayFunc(display)
    glut.glutIdleFunc(display)
    # glut.glutKeyboardFunc(keyboard)
    glut.glutPassiveMotionFunc(mouse)
    glut.glutSpecialFunc(keyboard)

    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glDepthFunc(gl.GL_LESS)
    gl.glClearColor(0, 0, 0, 0)

    vertices = np.array([
        -1, -1, 0,
        0, -1, -1,
        1, -1, 0,
        0, -1, 1,
        0, 1, 0
    ], dtype=np.float32)

    indexes = np.array([
        0, 1, 2,
        1, 2, 3,
        0, 1, 4,
        1, 2, 4,
        2, 3, 4,
        3, 0, 4
    ], dtype=np.uint32)

    vertex_shader = gl.glCreateShader(gl.GL_VERTEX_SHADER)
    gl.glShaderSource(vertex_shader, vertex_code)
    gl.glCompileShader(vertex_shader)

    if not gl.glGetShaderiv(vertex_shader, gl.GL_COMPILE_STATUS):
        info = gl.glGetShaderInfoLog(vertex_shader)
        print("vertex shader error occurred")
        print(bytes.decode(info))
        return

    fragment_shader = gl.glCreateShader(gl.GL_FRAGMENT_SHADER)
    gl.glShaderSource(fragment_shader, fragment_code)
    gl.glCompileShader(fragment_shader)

    if not gl.glGetShaderiv(fragment_shader, gl.GL_COMPILE_STATUS):
        info = gl.glGetShaderInfoLog(fragment_shader)
        print("fragment shader error occurred")
        print(bytes.decode(info))
        return

    program = gl.glCreateProgram()
    gl.glAttachShader(program, vertex_shader)
    gl.glAttachShader(program, fragment_shader)
    gl.glLinkProgram(program)
    gl.glUseProgram(program)

    vao = gl.glGenVertexArrays(1)
    gl.glBindVertexArray(vao)

    vbo = gl.glGenBuffers(1)
    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, vbo)
    gl.glBufferData(gl.GL_ARRAY_BUFFER, vertices.nbytes, vertices, gl.GL_STATIC_DRAW)
    gl.glEnableVertexAttribArray(0)
    gl.glVertexAttribPointer(0, 3, gl.GL_FLOAT, gl.GL_FALSE, 0, ctypes.c_void_p(0))

    ibo = gl.glGenBuffers(1)
    gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, ibo)
    gl.glBufferData(gl.GL_ELEMENT_ARRAY_BUFFER, indexes.nbytes, indexes, gl.GL_STATIC_DRAW)
    glut.glutMainLoop()
コード例 #16
0
ファイル: backend_glut.py プロジェクト: lordi/dantien
    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)
コード例 #17
0
ファイル: triangle.py プロジェクト: devforfu/pyogldev
def tiny_glut(args):
    global vertex_code, fragment_code
    scale = 0.01

    def display():
        CAMERA.render()
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        nonlocal scale
        scale_location = gl.glGetUniformLocation(program, "gScale")
        assert scale_location != 0xffffffff
        world_location = gl.glGetUniformLocation(program, "gWorld")
        assert world_location != 0xffffffff

        scale += 0.01

        pipeline = Pipeline(
            rotation=[0.0, 30 * scale, 0.0],
            # scaling=[math.sin(scale)] * 3,
            translation=[0, 0, 6],
            projection=ProjParams(WINDOW_WIDTH, WINDOW_HEIGHT, 1.0, 100.0,
                                  60.0))
        pipeline.set_camera(CAMERA)

        gl.glUniformMatrix4fv(world_location, 1, gl.GL_TRUE,
                              pipeline.get_wvp())
        gl.glDrawElements(gl.GL_TRIANGLES, 18, gl.GL_UNSIGNED_INT,
                          ctypes.c_void_p(0))
        glut.glutSwapBuffers()
        # glut.glutPostRedisplay()

    def mouse(x, y):
        CAMERA.mouse(x, y)

    def keyboard(key, x, y):
        if key == glut.GLUT_KEY_F1:
            sys.exit(0)
        elif key == glut.GLUT_KEY_HOME:
            CAMERA.setup()
        else:
            CAMERA.keyboard(key)

    glut.glutInit(args)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA
                             | glut.GLUT_3_2_CORE_PROFILE)
    glut.glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT)
    glut.glutInitWindowPosition(400, 100)
    # glut.glutCreateWindow("Camera Tutorial")
    glut.glutGameModeString("1920x1200@32")
    glut.glutEnterGameMode()

    # callbacks initialization
    glut.glutDisplayFunc(display)
    glut.glutIdleFunc(display)
    # glut.glutKeyboardFunc(keyboard)
    glut.glutPassiveMotionFunc(mouse)
    glut.glutSpecialFunc(keyboard)

    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glDepthFunc(gl.GL_LESS)
    gl.glClearColor(0, 0, 0, 0)

    vertices = np.array([-1, -1, 0, 0, -1, -1, 1, -1, 0, 0, -1, 1, 0, 1, 0],
                        dtype=np.float32)

    indexes = np.array([0, 1, 2, 1, 2, 3, 0, 1, 4, 1, 2, 4, 2, 3, 4, 3, 0, 4],
                       dtype=np.uint32)

    vertex_shader = gl.glCreateShader(gl.GL_VERTEX_SHADER)
    gl.glShaderSource(vertex_shader, vertex_code)
    gl.glCompileShader(vertex_shader)

    if not gl.glGetShaderiv(vertex_shader, gl.GL_COMPILE_STATUS):
        info = gl.glGetShaderInfoLog(vertex_shader)
        print("vertex shader error occurred")
        print(bytes.decode(info))
        return

    fragment_shader = gl.glCreateShader(gl.GL_FRAGMENT_SHADER)
    gl.glShaderSource(fragment_shader, fragment_code)
    gl.glCompileShader(fragment_shader)

    if not gl.glGetShaderiv(fragment_shader, gl.GL_COMPILE_STATUS):
        info = gl.glGetShaderInfoLog(fragment_shader)
        print("fragment shader error occurred")
        print(bytes.decode(info))
        return

    program = gl.glCreateProgram()
    gl.glAttachShader(program, vertex_shader)
    gl.glAttachShader(program, fragment_shader)
    gl.glLinkProgram(program)
    gl.glUseProgram(program)

    vao = gl.glGenVertexArrays(1)
    gl.glBindVertexArray(vao)

    vbo = gl.glGenBuffers(1)
    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, vbo)
    gl.glBufferData(gl.GL_ARRAY_BUFFER, vertices.nbytes, vertices,
                    gl.GL_STATIC_DRAW)
    gl.glEnableVertexAttribArray(0)
    gl.glVertexAttribPointer(0, 3, gl.GL_FLOAT, gl.GL_FALSE, 0,
                             ctypes.c_void_p(0))

    ibo = gl.glGenBuffers(1)
    gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, ibo)
    gl.glBufferData(gl.GL_ELEMENT_ARRAY_BUFFER, indexes.nbytes, indexes,
                    gl.GL_STATIC_DRAW)
    glut.glutMainLoop()
コード例 #18
0
ファイル: hex-grid.py プロジェクト: LiloD/vispy
    else:
        return


# Glut init
# --------------------------------------
glut.glutInit(sys.argv)
glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA)
glut.glutCreateWindow('Infinite hexagonal grid')
glut.glutReshapeWindow(512, 512)
glut.glutReshapeFunc(reshape)
glut.glutKeyboardFunc(keyboard)
glut.glutDisplayFunc(display)
glut.glutMotionFunc(on_motion)
glut.glutMouseFunc(on_mouse)
glut.glutPassiveMotionFunc(on_passive_motion)

# Build program & data
# --------------------------------------
program = Program(vertex, fragment, 4)
program['a_position'] = (-1, -1), (-1, +1), (+1, -1), (+1, +1)
program['a_texcoord'] = (0, 0), (0, +1), (+1, 0), (+1, +1)
program['u_grid_color'] = 0, 0, 0, 1
program['u_grid_thickness'] = 1
program['u_grid_antialias'] = .75
program['u_translate'] = 0, 0
program['u_scale'] = 1.0
program['u_size'] = 512, 512

mouse = 400, 400
translate = [0, 0]
コード例 #19
0
        boosts.clear()
        heart_remove_order.queue.clear()
        boost_remove_order.queue.clear()
        hearts.clear()
        boost_remove_order_New = queue.Queue()
        heart_remove_order_New = queue.Queue()
        for j in initial_hearts:
            j.join_set(hearts)
            heart_remove_order_New.put(j)
        for k in temp_boosts:
            k.join_set(boosts)
            boost_remove_order_New.put(k)
        boost_remove_order = boost_remove_order_New
        heart_remove_order = heart_remove_order_New


# glut.glutKeyboardFunc(keyboard_input)


def mouse_passive_motion(x, y):
    # print(x, y)
    a = x


glut.glutSetCursor(glut.GLUT_CURSOR_NONE)
glut.glutPassiveMotionFunc(mouse_passive_motion)

# Start the Main Loop ----------------------------------------------------------------|

glut.glutMainLoop()
コード例 #20
0
ファイル: flightsim.py プロジェクト: suBDavis/jankulous-rift
       xrot = -(x-500.) / 1000
       yrot = (y - 500.) / 1000
      
       rotator = np.matrix([[np.cos(xrot), np.sin(xrot), 0],
                                 [-np.sin(xrot),np.cos(xrot), 0],
                                 [0,           0,             1]])
       rotator *= np.matrix([[1, 0, 0],
                            [0,np.cos(yrot), np.sin(yrot)],
                            [0,-np.sin(yrot),np.cos(yrot)]])
       
       orientation = rotator * orientation
       
       GLUT.glutWarpPointer(500, 500)

                            
GLUT.glutPassiveMotionFunc(mousemoved)
GLUT.glutDisplayFunc(draw)
print len(norms)

def update():
    global position, orientation
    t0 = time.time()
    orientation = (rotator**-1) * orientation
    go = np.array((orientation** -1) * np.matrix([[0], [0], [.2]])).flatten()
    
    position[0] += go[0] 
    position[1] += go[1]
    position[2] += go[2]
    draw()
    t1 = time.time()
    if heightfunc(-position[2], -position[0]) > -position[1]:
コード例 #21
0
    data['a_size'][index] = 5
    data['a_fg_color'][index] = 0, 0, 0, 1
    index = (index + 1) % 500
    glut.glutPostRedisplay()


# Glut init
# --------------------------------------
glut.glutInit(sys.argv)
glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH)
glut.glutCreateWindow('Rain [Move mouse]')
glut.glutReshapeWindow(512, 512)
glut.glutReshapeFunc(reshape)
glut.glutKeyboardFunc(keyboard)
glut.glutDisplayFunc(display)
glut.glutPassiveMotionFunc(on_passive_motion)
glut.glutTimerFunc(1000 / 60, timer, 60)

# Build data
# --------------------------------------
n = 500
data = np.zeros(n, [('a_position', np.float32, 2),
                    ('a_fg_color', np.float32, 4), ('a_size', np.float32, 1)])
index = 0

# Build program
# --------------------------------------
program = Program(vertex, fragment)
vdata = VertexBuffer(data)
program.bind(vdata)
program['u_antialias'] = 1.00
コード例 #22
0
ファイル: glutwindow.py プロジェクト: padeler/PyGLer
    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)
コード例 #23
0
    elif key == 'p':
        running = not running

#the mouse is used to control the camera
def mouse(button, state, x, y):
    if button == GLUT.GLUT_LEFT_BUTTON:
        if (state == GLUT.GLUT_DOWN):
            GLUT.glutIdleFunc(forward)
        elif (state == GLUT.GLUT_UP):
            GLUT.glutIdleFunc(Calculations)
    elif button == GLUT.GLUT_RIGHT_BUTTON:
        if (state == GLUT.GLUT_DOWN):
            GLUT.glutIdleFunc(backward)
        elif (state == GLUT.GLUT_UP):
            GLUT.glutIdleFunc(Calculations)

GLUT.glutInit(sys.argv)
GLUT.glutInitDisplayMode (GLUT.GLUT_DOUBLE | GLUT.GLUT_RGB | GLUT.GLUT_DEPTH)
GLUT.glutInitWindowSize (1024, 576)
GLUT.glutInitWindowPosition (100, 100)
GLUT.glutCreateWindow('Lorentz Attractor')
init()
GL.glEnable(GL.GL_TEXTURE_2D)
GLUT.glutDisplayFunc(display)
GLUT.glutReshapeFunc(reshape)
GLUT.glutKeyboardFunc(keyboard)
GLUT.glutMouseFunc(mouse)
GLUT.glutPassiveMotionFunc(motion)
GLUT.glutMotionFunc(motion)
GLUT.glutIdleFunc(Calculations)
GLUT.glutMainLoop()