Ejemplo n.º 1
0
def key_event(window, key, scancode, action, mods):
    if action == glfw.PRESS:
        if key == glfw.KEY_ESCAPE:
            glfw.SetWindowShouldClose(window, True)
            print("ESC")
        elif key == glfw.KEY_A:
            gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE)
            print("A _FILL")
        elif key == glfw.KEY_S:
            gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)
            print("S_LINE")
    elif action == glfw.REPEAT:
        global cam_angle_xz
        global cam_angle_xy
        if key == glfw.KEY_RIGHT:
            cam_angle_xz-=0.4
            print("RIGHT")
        elif key == glfw.KEY_LEFT:
            cam_angle_xz+=0.4
            print("LEFT")
        elif key == glfw.KEY_UP:
            cam_angle_xy+=0.4
            print("UP")
        elif key == glfw.KEY_DOWN:
            cam_angle_xy-=0.4
            print("DOWN")
    camera.x=cam_radius * (math.cos(cam_angle_xz))
    camera.y=cam_radius * (math.sin(cam_angle_xy))
    camera.z=cam_radius * (math.sin(cam_angle_xz))
Ejemplo n.º 2
0
 def on_keydown(window, key, scancode, action, mods):
     if key == glfw.KEY_ESCAPE and action == glfw.PRESS:
         glfw.SetWindowShouldClose(window, gl.GL_TRUE)
     elif action == glfw.PRESS:
         key_state[key] = True
     elif action == glfw.RELEASE:
         key_state[key] = False
Ejemplo n.º 3
0
    def _on_keyboard(self, window, key, scancode, action, mods):
        # logger.debug('Keyboard: key={}, scancode={}, action={}, mods={}'.format(key, scancode, action, mods))
        if action == glfw.PRESS:
            if key == glfw.KEY_LEFT_ALT:
                self._print_cursor_position()
            if key == glfw.KEY_P:  # Change camera mode perspective/ortho
                if self._camera.mode is CameraMode.perspective:
                    self._camera.mode = CameraMode.ortho
                    self.update()
                else:
                    assert self._camera.mode is CameraMode.ortho
                    self._camera.mode = CameraMode.perspective
                    self.update()
                logger.debug('Using {} camera!'.format(
                    self._camera.mode.value))
            if key == glfw.KEY_E:  # Edge rendering mode enable/disable
                self._edges_mode = not self._edges_mode
                logger.debug('Rendering edges mode: {}!'.format(
                    'enabled' if self._edges_mode else 'disabled'))
                self.update()
            if key == glfw.KEY_ESCAPE:  # Close window
                glfw.SetWindowShouldClose(self._window, True)
                self.update()
            if key == glfw.KEY_S:  # Render current frustum and save as screenshot to screenshot.png and screenshot_depth.png
                self._to_do.append(self._make_screenshot_and_save())
                self.update()
            self._keyboard_buttons_down[key] = mods
        elif action == glfw.RELEASE:
            if key in self._keyboard_buttons_down:
                del self._keyboard_buttons_down[key]

        for cb in self._on_keyboard_callbacks.values():
            cb(window, key, scancode, action, mods)
Ejemplo n.º 4
0
    def run_loop(self):
        glfw.MakeContextCurrent(self._win)

        glfw.SetWindowShouldClose(self._win, False)
        while not glfw.WindowShouldClose(self._win):
            if self._next_renderer:
                if self._renderer:
                    self._renderer.dispose()

                self._renderer = self._next_renderer
                self._renderer.prepare()

                self._next_renderer = None

            glClearColor(0.5, 0.5, 0.5, 1.0)
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
            if self._renderer:
                self._renderer.render()

            glfw.SwapBuffers(self._win)

            # Poll for and process events
            glfw.PollEvents()

        if self._renderer:
            self._renderer.dispose()
        if self._next_renderer is None:
            self._next_renderer = self._renderer
Ejemplo n.º 5
0
        def key_callback(window, key, scancode, action, mods):
            if (key == glfw.KEY_ESCAPE and action == glfw.PRESS):
                glfw.SetWindowShouldClose(window, True)

            if (action == glfw.PRESS and key == glfw.KEY_L):
                self.cameraLocked = not self.cameraLocked
                print 'cameraLocked:', self.cameraLocked

                glfw.SetInputMode(window, glfw.CURSOR, glfw.CURSOR_NORMAL if self.cameraLocked else glfw.CURSOR_DISABLED)

                # if not self.cameraLocked:
                # Ensure that locking/unlocking doesn't move the view:
                windowWidth, windowHeight = glfw.GetWindowSize(window)
                glfw.SetCursorPos(window, windowWidth / 2, windowHeight / 2)
                self.currentCamera.lastCursor = np.array(glfw.GetCursorPos(window), np.float32)
                self.currentCamera.lastUpdateTime = glfw.GetTime()

            if (action == glfw.PRESS and key == glfw.KEY_R):
                self.mainRender.renderCairo(self.playerCamera, self.cairoSavePath)

            pass
Ejemplo n.º 6
0
def close_window(event_coll, event):
    '''Close main window'''
    glfw.SetWindowShouldClose(event.window, True)
Ejemplo n.º 7
0
 def key_callback(self, window, key, scancode, action, mods):
     """press ESCAPE to quite the application"""
     if key == glfw.KEY_ESCAPE and action == glfw.PRESS:
         glfw.SetWindowShouldClose(self.window, True)
Ejemplo n.º 8
0
 def on_keydown(window, key, scancode, action, mods):
     if key == glfw.KEY_ESCAPE and action == glfw.PRESS:
         glfw.SetWindowShouldClose(window, gl.GL_TRUE)
Ejemplo n.º 9
0
def close_window(event_coll, event):
    """Close main window"""
    glfw.SetWindowShouldClose(event.window, True)
Ejemplo n.º 10
0
 def key_callback(window, key, scancode, action, mode):
     if action == glfw.PRESS:
         if key == glfw.KEY_ESCAPE:
             glfw.SetWindowShouldClose(window, True)
Ejemplo n.º 11
0
 def test_should_close(self):
     window = glfw.CreateWindow(640, 480, 'Should close')
     glfw.SetWindowShouldClose(window, True)
     self.assertTrue(glfw.WindowShouldClose(window))
     glfw.DestroyWindow(window)
def create_cursor_from_pixels(pixels, W, H):
    image = glfw.Image()
    im = 255 * np.ones((H, W, 4), dtype=np.uint8)
    im[:, :, :pixels.shape[2]] = pixels
    image.pixels = im
    return glfw.CreateCursor(image, W / 2, H / 2)


def create_cursor(icon_path, W, H):
    pixels = Image.open(icon_path)
    pixels = np.array(pixels.resize((W, H), Image.ANTIALIAS))
    return create_cursor_from_pixels(pixels, W, H)


#glfw.IconifyWindow(window)
#glfw.RestoreWindow(window)

cursor = create_cursor(
    '/home/dimitri/Pictures/Screenshot from 2017-08-06 15-04-26.png', 128, 128)
glfw.SetCursor(window, cursor)

i = 0
while not glfw.WindowShouldClose(window):

    glfw.SwapBuffers(window)
    glfw.PollEvents()

glfw.SetWindowTitle(window, "My Window")

glfw.SetWindowShouldClose(window, True)