def on_key(window, key, scancode, action, mods): if action != glfw.PRESS: return global controller if key == glfw.KEY_SPACE: controller.rotate = not controller.rotate elif key == glfw.KEY_LEFT: controller.x -= 0.1 elif key == glfw.KEY_RIGHT: controller.x += 0.1 elif key == glfw.KEY_UP: controller.y += 0.1 elif key == glfw.KEY_DOWN: controller.y -= 0.1 elif key == glfw.KEY_ESCAPE: glfw.set_window_should_close(window, True) else: print('Unknown key')
def inicializaRenderizacao(): global Window, Shader_programm, Vao, WIDTH, HEIGHT while not glfw.window_should_close(Window): glClear(GL_COLOR_BUFFER_BIT) glClearColor(0.2, 0.3, 0.3, 1.0) glViewport(0, 0, WIDTH, HEIGHT) glUseProgram(Shader_programm) #ativa o shader #desenha o quadrado glBindVertexArray(Vao_quadrado) glDrawArrays(GL_TRIANGLES, 0, 6) #desenha o triângulo glBindVertexArray(Vao_triangulo) glDrawArrays(GL_TRIANGLES, 0, 3) glfw.poll_events() #recebe eventos de mouse e teclado glfw.swap_buffers(Window) #realiza a troca de buffers para renderizar de fato o que foi desenhado acima if (glfw.PRESS == glfw.get_key(Window, glfw.KEY_ESCAPE)): #trata os eventos de mouse e teclado glfw.set_window_should_close(Window, True) glfw.terminate()
def key_callback(window, key, scancode, action, mods): global pos_x_tr global pos_y_tr #eventos: press, release, repeat #if key == glfw.KEY_ESCAPE: # if action == glfw.PRESS: # print("Se dectecto un press en tecla ESC") # if action == glfw.RELEASE: # print("Se dectecto un release en tecla ESC") # if action == glfw.REPEAT: # print("Se dectecto un repeat en tecla ESC") if key == glfw.KEY_ESCAPE and action == glfw.PRESS: glfw.set_window_should_close(window, 1) if action == glfw.PRESS or action == glfw.REPEAT: if key == glfw.KEY_LEFT: pos_x_tr = pos_x_tr - 0.05 if key == glfw.KEY_RIGHT: pos_x_tr = pos_x_tr + 0.05 if key == glfw.KEY_DOWN: pos_y_tr = pos_y_tr - 0.05 if key == glfw.KEY_UP: pos_y_tr = pos_y_tr + 0.05
def processInput(self): if glfw.get_key(self.window, glfw.KEY_ESCAPE) == glfw.PRESS: glfw.set_window_should_close(self.window, True) if glfw.get_key(self.window, glfw.KEY_SPACE) == glfw.PRESS: gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE) else: gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL) # Speed managment leftPressed = glfw.get_key(self.window, glfw.KEY_LEFT) if leftPressed == glfw.PRESS: if not self.pressed["left"]: if self.speed <= 1/16: self.speed = 0 else: self.speed /= 2 if self.speed > 1: self.speed = round(self.speed) self.speed = max(self.speed, 1/16) self.pressed["left"] = leftPressed rightPressed = glfw.get_key(self.window, glfw.KEY_RIGHT) if rightPressed == glfw.PRESS: if not self.pressed["right"]: if self.speed == 0: self.speed = 1/16 else: self.speed *= 2 if self.speed > 1: self.speed = round(self.speed) self.speed = min(self.speed, 2**10) self.pressed["right"] = rightPressed if self.camera is not None: self.camera.processInput(self.window, self._deltaTime)
def key_callback(window, key, scancode, action, mods): if (key == glfw.KEY_ESCAPE and action == glfw.PRESS): glfw.set_window_should_close(window, GL_TRUE) return; move_speed = 6.0 camera_pos = matrixScene.camera_pos direction = matrixScene.direction right = matrixScene.right if (key == glfw.KEY_W): camera_pos += direction * time.GetTimeDelta() * move_speed; if (key == glfw.KEY_S): camera_pos -= direction * time.GetTimeDelta() * move_speed; if (key == glfw.KEY_A): camera_pos -= right * time.GetTimeDelta() * move_speed; if (key == glfw.KEY_D): camera_pos += right * time.GetTimeDelta() * move_speed; #set new camera_pos and calculate matrix matrixScene.camera_pos = camera_pos matrixScene.calculate_view_matrix() note.info(matrixScene.camera_pos)
def inicializaRenderizacao(): global Window, Shader_programm, Vao, WIDTH, HEIGHT while not glfw.window_should_close(Window): glClear(GL_COLOR_BUFFER_BIT) glClearColor(0.2, 0.3, 0.3, 1.0) glViewport(0, 0, WIDTH, HEIGHT) glUseProgram(Shader_programm) #ativa o shader glBindVertexArray(Vao) #ativa o objeto a ser renderizado transformaQuadrado( ) #configura o valor da variavel "matriz" do shader, que corresponde a transformações geométricas glDrawArrays(GL_TRIANGLES, 0, 6) #renderiza o objeto glfw.poll_events() glfw.swap_buffers(Window) if (glfw.PRESS == glfw.get_key(Window, glfw.KEY_ESCAPE)): glfw.set_window_should_close(Window, True) glfw.terminate()
def close(self): """Close the window and uninitialize the resources """ # Test if the window has already been closed if glfw.window_should_close(self.winHandle): return _hw_handle = None try: self.setMouseVisibility(True) glfw.set_window_should_close(self.winHandle, 1) glfw.destroy_window(self.winHandle) except Exception: pass # If iohub is running, inform it to stop looking for this win id # when filtering kb and mouse events (if the filter is enabled of # course) try: if IOHUB_ACTIVE and _hw_handle: from psychopy.iohub.client import ioHubConnection conn = ioHubConnection.ACTIVE_CONNECTION conn.unregisterWindowHandles(_hw_handle) except Exception: pass
def key_event(win, key, scancode, action, mods): global selfstatic if action == glfw.PRESS: # ESC to quit if key == glfw.KEY_ESCAPE: print('esc') glfw.set_window_should_close(win, True) elif key == glfw.KEY_TAB: selfstatic.selected_obj += 1 if selfstatic.selected_obj >= len(selfstatic.map.objs): selfstatic.selected_obj = 0 selfstatic.oo = selfstatic.map.objs[selfstatic.selected_obj] elif key == glfw.KEY_LEFT: print('left') selfstatic.map.move_left(10) elif key == glfw.KEY_RIGHT: print('right') selfstatic.map.move_right(10) elif key == glfw.KEY_UP: print('up') selfstatic.map.move_forward() elif key == glfw.KEY_DOWN: print('down') selfstatic.map.move_back() elif key == glfw.KEY_KP_SUBTRACT: selfstatic.map.rotate(-5) elif key == glfw.KEY_KP_ADD: selfstatic.map.rotate(5)
def keyboard_input(self, win, key, scancode, action, mods): #self.logger.debug('key: {}, scancode: {}, action: {}, mods: {}'.format(key, scancode, action, mods)) if (key == glfw.KEY_ESCAPE ) or (mods == glfw.MOD_ALT and key == glfw.KEY_F4) and action == glfw.PRESS: glfw.set_window_should_close(self.window, True) self.logger.info('Exiting') if key == glfw.KEY_H and action == glfw.PRESS: self.ui.toggle_visibility() self.logger.debug('Toggle UI') if key == glfw.KEY_W and action != glfw.RELEASE: self.camera.move_forward() if key == glfw.KEY_A and action != glfw.RELEASE: self.camera.move_left() if key == glfw.KEY_S and action != glfw.RELEASE: self.camera.move_backward() if key == glfw.KEY_D and action != glfw.RELEASE: self.camera.move_right() if key == glfw.KEY_Q and action != glfw.RELEASE: self.camera.move_up() if key == glfw.KEY_E and action != glfw.RELEASE: self.camera.move_down() if key == glfw.KEY_R and action == glfw.PRESS: self.camera.reset() if key == glfw.KEY_P and action == glfw.PRESS: self.freeze_time = not self.freeze_time self.logger.info('Toggle time freeze') if key == glfw.KEY_F and action == glfw.PRESS: self.camera.toggle_look_mode() self.logger.info('Toggle camera look mode') if key == glfw.KEY_T and action == glfw.PRESS: self.ui.toggle_composition_overlay() self.logger.info('Toggle composition overlay')
def on_key(self, _win, key, _scancode, action, _mods): """ 'Q' or 'Escape' quits """ if action == glfw.PRESS or action == glfw.REPEAT: if key == glfw.KEY_ESCAPE or key == glfw.KEY_Q: glfw.set_window_should_close(self.win, True) elif key == glfw.KEY_N: self.color_id = (self.color_id + 1) % 3
def on_key(self, _win, key, _scancode, action, _mods): """ 'Q' or 'Escape' quits """ if action == glfw.PRESS or action == glfw.REPEAT: if key == glfw.KEY_ESCAPE or key == glfw.KEY_Q: glfw.set_window_should_close(self.win, True) if key == glfw.KEY_W: GL.glPolygonMode(GL.GL_FRONT_AND_BACK, next(self.fill_modes))
def processInput(window): # global rotate, rpressed global cameraPos, cameraFront, ipressed if glfw.get_key(window, glfw.KEY_ESCAPE) == glfw.PRESS: glfw.set_window_should_close(window, True) if glfw.get_key(window, glfw.KEY_W) == glfw.PRESS: camera.processKeyboard(mycamera.FORWARD, deltaTime) if glfw.get_key(window, glfw.KEY_S) == glfw.PRESS: camera.processKeyboard(mycamera.BACKWARD, deltaTime) if glfw.get_key(window, glfw.KEY_A) == glfw.PRESS: camera.processKeyboard(mycamera.LEFT, deltaTime) if glfw.get_key(window, glfw.KEY_D) == glfw.PRESS: camera.processKeyboard(mycamera.RIGHT, deltaTime) if glfw.get_key(window, glfw.KEY_Q) == glfw.PRESS: camera.processKeyboard(mycamera.UP, deltaTime) if glfw.get_key(window, glfw.KEY_Z) == glfw.PRESS: camera.processKeyboard(mycamera.DOWN, deltaTime) if glfw.get_key(window, glfw.KEY_I) == glfw.PRESS: if not ipressed: print(f"lastX: {lastX:3.2f}, lastY: {lastY:3.2f}") print(f"fps: {1/deltaTime:3.1f}") print(camera) ipressed = True if glfw.get_key(window, glfw.KEY_I) == glfw.RELEASE: ipressed = False camera.step(deltaTime)
def key_callback(window, key, scancode, action, mods): global pos_x_triangulo global pos_y_triangulo #if key == glfw.KEY_ESCAPE: #if action == glfw.PRESS: #print("Se detectó un press") #if action == glfw.RELEASE: #print("Se detectó un release") #if action == glfw.REPEAT: #print("Se detectó un repeawt") if key == glfw.KEY_ESCAPE and action == glfw.PRESS: glfw.set_window_should_close(window, 1) if action == glfw.PRESS or action == glfw.REPEAT: if key == glfw.KEY_LEFT: pos_x_triangulo = pos_x_triangulo - 0.05 if key == glfw.KEY_RIGHT: pos_x_triangulo = pos_x_triangulo + 0.05 if key == glfw.KEY_DOWN: pos_y_triangulo = pos_y_triangulo - 0.05 if key == glfw.KEY_UP: pos_y_triangulo = pos_y_triangulo + 0.05
def trataTeclado(): global Cam_pos, Cam_yaw, Cam_yaw_speed, Tempo_entre_frames if (glfw.PRESS == glfw.get_key(Window, glfw.KEY_ESCAPE)): glfw.set_window_should_close(Window, True) if (glfw.PRESS == glfw.get_key(Window, glfw.KEY_A)): Cam_pos[0] -= Cam_speed * Tempo_entre_frames if (glfw.PRESS == glfw.get_key(Window, glfw.KEY_D)): Cam_pos[0] += Cam_speed * Tempo_entre_frames if (glfw.PRESS == glfw.get_key(Window, glfw.KEY_PAGE_UP)): Cam_pos[1] += Cam_speed * Tempo_entre_frames if (glfw.PRESS == glfw.get_key(Window, glfw.KEY_PAGE_DOWN)): Cam_pos[1] -= Cam_speed * Tempo_entre_frames if (glfw.PRESS == glfw.get_key(Window, glfw.KEY_W)): Cam_pos[2] -= Cam_speed * Tempo_entre_frames if (glfw.PRESS == glfw.get_key(Window, glfw.KEY_S)): Cam_pos[2] += Cam_speed * Tempo_entre_frames if (glfw.PRESS == glfw.get_key(Window, glfw.KEY_LEFT)): Cam_yaw += Cam_yaw_speed * Tempo_entre_frames if (glfw.PRESS == glfw.get_key(Window, glfw.KEY_RIGHT)): Cam_yaw -= Cam_yaw_speed * Tempo_entre_frames
def on_key(self, _win, key, _scancode, action, _mods): if action == glfw.PRESS: """ 'Q' or 'Escape' quits """ if key == glfw.KEY_ESCAPE or key == glfw.KEY_Q: glfw.set_window_should_close(self.win, True) """ 'R' reloads shader files """ if key == key == glfw.KEY_R: self.ray_tracer = Shader(vs_file, fs_file) self.reload = True if self.ray_tracer.glid: print('Shader successfully reloaded.') if key == glfw.KEY_G: f = open(fs_file, "r") l = f.readline() l2 = f.readline() f.close() p = re.compile("@FROM (.*)") input_path = p.search(l).group(1) p = re.compile("@TO (.*)") output_dir = p.search(l2).group(1) if input_path[0] == "/": input_path = input_path[1:] if output_dir[0] == "/": output_dir = output_dir[1:] generate(input_path, output_dir, True) self.ray_tracer = Shader(vs_file, fs_file) self.reload = True if self.ray_tracer.glid: print('Shader successfully reloaded.')
def run(*windows): if not glfw.init(): raise Exception("can't initialize glfw") if os.path.exists("gamecontrollerdb.txt"): with open("gamecontrollerdb.txt", "r") as file: gamecontrollerdb = file.read() glfw.update_gamepad_mappings(gamecontrollerdb) glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3) # 3.2 or 4.1 glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 2) glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, 1) glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE) glfw.window_hint(glfw.COCOA_RETINA_FRAMEBUFFER, False) for window in windows: window.show() try: windows_open = True while windows_open: windows_open = False for window in windows: windows_open |= window.update() glfw.poll_events() except KeyboardInterrupt: for window in windows: glfw.set_window_should_close(window.window, True) glfw.terminate()
def KeyInputCallback(window, key, scancode, action, mods): """ Функция отслеживания нажатий клавиш клавиатуры """ global left, right, forward, backward global light_movement # закрытие окна по нажатию на Esc if key == glfw.KEY_ESCAPE and action == glfw.PRESS: glfw.set_window_should_close(window, glfw.TRUE) if key == glfw.KEY_SPACE and action == glfw.PRESS: light_movement = not light_movement if key == glfw.KEY_W and action == glfw.PRESS: forward = True elif key == glfw.KEY_W and action == glfw.RELEASE: forward = False if key == glfw.KEY_S and action == glfw.PRESS: backward = True elif key == glfw.KEY_S and action == glfw.RELEASE: backward = False if key == glfw.KEY_A and action == glfw.PRESS: left = True elif key == glfw.KEY_A and action == glfw.RELEASE: left = False if key == glfw.KEY_D and action == glfw.PRESS: right = True elif key == glfw.KEY_D and action == glfw.RELEASE: right = False
def key_callback(window, key, scancode, action, mods): print('key_callback', key, scancode, action, mods) if key == 256: glfw.set_window_should_close(window, True) if action == 1 or action == 2: if key == 61 and mods == 1: camera_target.zoom = min(9, max(1, camera_target.zoom + 1)) if key == 47 and mods == 0: camera_target.zoom = min(9, max(1, camera_target.zoom - 1)) if action == 1: if key == 65 and mods == 0: camera_target.dx[0] = .05 if key == 68 and mods == 0: camera_target.dx[1] = .05 if key == 83 and mods == 0: camera_target.dy[0] = .05 if key == 87 and mods == 0: camera_target.dy[1] = .05 if action == 0: if key == 65 and mods == 0: camera_target.dx[0] = 0 if key == 68 and mods == 0: camera_target.dx[1] = 0 if key == 83 and mods == 0: camera_target.dy[0] = 0 if key == 87 and mods == 0: camera_target.dy[1] = 0
def key_callback(window, key, scancode, action, mods): global pos_x_triangulo global pos_y_triangulo #Press: al momento de presionar #release: hasta que dejas de presionar #repeat: cada repeticion es un evento #if key == glfw.KEY_ESCAPE: # if action == glfw.PRESS: # print("Se detecto un press de la tecla escape") # if action == glfw.RELEASE: # print("Se detecto un release de la tecla escape") # if action == glfw.REPEAT: # print("Se detecto un repeat de la tecla escape") if key == glfw.KEY_ESCAPE and action == glfw.PRESS: glfw.set_window_should_close(window, 1) if action == glfw.PRESS or action == glfw.REPEAT: if key == glfw.KEY_LEFT: pos_x_triangulo = pos_x_triangulo - 0.05 if key == glfw.KEY_RIGHT: pos_x_triangulo = pos_x_triangulo + 0.05 if key == glfw.KEY_DOWN: pos_y_triangulo = pos_y_triangulo - 0.05 if key == glfw.KEY_UP: pos_y_triangulo = pos_y_triangulo + 0.05
def callback_teclado(self, janela, key, scancode, action, mods): if key is glfw.KEY_ESCAPE: glfw.set_window_should_close(janela, True) elif key is glfw.KEY_A: self.mover_triangulo_esq() elif key is glfw.KEY_D: self.mover_triangulo_dir()
def _restart_with_recording(rec_dir): logger.debug("Starting new session with '{}'".format(rec_dir)) ipc_pub.notify({ "subject": "player_drop_process.should_start", "rec_dir": rec_dir }) glfw.set_window_should_close(g_pool.main_window, True)
def key_callback(window, key, scancode, action, mods): global background_color global foreground_color global texture_image global texture_data global model_data global color global model global ctx # Escape or 'q' will exit if key in [glfw.KEY_ESCAPE, glfw.KEY_Q] and action == glfw.PRESS: glfw.set_window_should_close(window, True) elif key in [glfw.KEY_F] and action == glfw.PRESS: # Cycle the background color foreground_color = next(color) elif key in [glfw.KEY_B] and action == glfw.PRESS: # Cycle the background color background_color = next(color) elif key in [glfw.KEY_M] and action == glfw.PRESS: # Cycle the object model model_data = next(model) elif key in [glfw.KEY_T] and action == glfw.PRESS: # Cycle the texture texture_image = next(texture) texture_data = ctx.texture(texture_image.size, 3, texture_image.tobytes()) texture_data.build_mipmaps()
def close(self): """Close the window and uninitialize the resources """ # Test if the window has already been closed if glfw.window_should_close(self.winHandle): return _hw_handle = None try: self.setMouseVisibility(True) glfw.set_window_should_close(self.winHandle, 1) glfw.destroy_window(self.winHandle) except Exception: pass # If iohub is running, inform it to stop looking for this win id # when filtering kb and mouse events (if the filter is enabled of # course) try: if window.IOHUB_ACTIVE and _hw_handle: from psychopy.iohub.client import ioHubConnection conn = ioHubConnection.ACTIVE_CONNECTION conn.unregisterWindowHandles(_hw_handle) except Exception: pass
def key_input_clb(window, key, scancode, action, mode): global left, right, forward, backward, Rotate, quake if key == glfw.KEY_ESCAPE and action == glfw.PRESS: glfw.set_window_should_close(window, True) if key == glfw.KEY_W and action == glfw.PRESS: forward = True elif key == glfw.KEY_W and action == glfw.RELEASE: forward = False if key == glfw.KEY_S and action == glfw.PRESS: backward = True elif key == glfw.KEY_S and action == glfw.RELEASE: backward = False if key == glfw.KEY_A and action == glfw.PRESS: left = True elif key == glfw.KEY_A and action == glfw.RELEASE: left = False if key == glfw.KEY_D and action == glfw.PRESS: right = True elif key == glfw.KEY_D and action == glfw.RELEASE: right = False if key == glfw.KEY_R and action == glfw.PRESS: Rotate = not Rotate if key == glfw.KEY_E and action == glfw.PRESS: quake = not quake
def inicializaRenderizacao(): global Window, Shader_programm, Vao, WIDTH, HEIGHT while not glfw.window_should_close(Window): glClear(GL_COLOR_BUFFER_BIT) glClearColor(0.2, 0.3, 0.3, 1.0) glViewport(0, 0, WIDTH, HEIGHT) #desenha o quadrado glUseProgram(Shader_programm_quadrado) #ativa o shader do quadrado glBindVertexArray(Vao_quadrado) #ativa o VAO do quadrado glDrawArrays(GL_TRIANGLES, 0, 6) #renderiza o quadrado #desenha o triângulo glUseProgram(Shader_programm_triangulo) #troca de shader, ativando o shader do triangulo glBindVertexArray(Vao_triangulo) #troca de VAO, ativando o VAO do triângulo glDrawArrays(GL_TRIANGLES, 0, 3) #renderiza o triângulo glfw.poll_events() glfw.swap_buffers(Window) if (glfw.PRESS == glfw.get_key(Window, glfw.KEY_ESCAPE)): glfw.set_window_should_close(Window, True) glfw.terminate()
def process_input(window): if glfw.get_key(window, glfw.KEY_ESCAPE) == glfw.PRESS: glfw.set_window_should_close(window, True) if glfw.get_key(window, glfw.KEY_LEFT) == glfw.PRESS: gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL) if glfw.get_key(window, glfw.KEY_RIGHT) == glfw.PRESS: gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE)
def key_callback(window, key, scancode, action, mode): global state if key == glfw.KEY_ESCAPE and action == glfw.PRESS: glfw.set_window_should_close(window, GL_TRUE) elif key == glfw.KEY_A and action == glfw.PRESS: state = 1 - state
def key_input_clb(window, key, scancode, action, mode): global CAM_MOVE_FOR, CAM_MOVE_BACK, CAM_MOVE_LEFT, CAM_MOVE_RIGHT, light_index if key == glfw.KEY_ESCAPE and action == glfw.PRESS: glfw.set_window_should_close(window, True) elif key == glfw.KEY_S: CAM_MOVE_FOR = False if action == glfw.RELEASE else True elif key == glfw.KEY_W: CAM_MOVE_BACK = False if action == glfw.RELEASE else True elif key == glfw.KEY_A: CAM_MOVE_LEFT = False if action == glfw.RELEASE else True elif key == glfw.KEY_D: CAM_MOVE_RIGHT = False if action == glfw.RELEASE else True elif key == glfw.KEY_PAGE_UP: light_pos[light_index] += .2 elif key == glfw.KEY_PAGE_DOWN: light_pos[light_index] -= .2 elif key == glfw.KEY_X: light_index = 0 elif key == glfw.KEY_Y: light_index = 1 elif key == glfw.KEY_Z: light_index = 2
def key_callback(window, key, scancode, action, mods): global keystat, player if action == glfw.PRESS: if key == glfw.KEY_UP or key == glfw.KEY_W: keystat.FORWARD = True elif key == glfw.KEY_DOWN or key == glfw.KEY_S: keystat.BACK = True elif key == glfw.KEY_LEFT or key == glfw.KEY_A: keystat.LEFT = True elif key == glfw.KEY_RIGHT or key == glfw.KEY_D: keystat.RIGHT = True elif key == glfw.KEY_SPACE: keystat.JUMP = True elif key == glfw.KEY_LEFT_SHIFT: keystat.LAND = True elif key == glfw.KEY_P: # For debugging print("player at (", int(player.x), ", ", int(player.y), ", ", int(player.z), ")") elif key == glfw.KEY_R: # recreate the world new_world() elif key == glfw.KEY_ESCAPE: # show mouse cursor cursor_x = -1 cursor_y = -1 glfw.set_input_mode(window, glfw.CURSOR, glfw.CURSOR_NORMAL) elif key == glfw.KEY_Q: # close window glfw.set_window_should_close(window, GL_TRUE) elif key == glfw.KEY_1: player.holding = 1 elif key == glfw.KEY_2: player.holding = 2 elif key == glfw.KEY_3: player.holding = 3 elif key == glfw.KEY_4: player.holding = 4 elif key == glfw.KEY_5: player.holding = 5 elif key == glfw.KEY_6: player.holding = 6 elif key == glfw.KEY_7: player.holding = 7 elif key == glfw.KEY_8: player.holding = 8 elif key == glfw.KEY_9: player.holding = 9 elif action == glfw.RELEASE: if key == glfw.KEY_UP or key == glfw.KEY_W: keystat.FORWARD = False elif key == glfw.KEY_DOWN or key == glfw.KEY_S: keystat.BACK = False elif key == glfw.KEY_LEFT or key == glfw.KEY_A: keystat.LEFT = False elif key == glfw.KEY_RIGHT or key == glfw.KEY_D: keystat.RIGHT = False elif key == glfw.KEY_SPACE: keystat.JUMP = False elif key == glfw.KEY_LEFT_SHIFT: keystat.LAND = False return
def main(self): glfw.set_error_callback(error_callback) if not glfw.init(): raise RuntimeError('glfw.init()') glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, True) glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE) glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3) glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3) glfw.window_hint(glfw.SAMPLES, 4) glfw.window_hint(glfw.RESIZABLE, False) self.window = glfw.create_window(self.screen_x, self.screen_y, self.title, None, None) if not self.window: raise RuntimeError('glfw.CreateWindow())') glfw.make_context_current(self.window) glfw.set_input_mode(self.window, glfw.CURSOR, glfw.CURSOR_DISABLED) glfw.set_cursor_pos(self.window, 0, 0) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_DEPTH_TEST) glDepthFunc(GL_LESS) glClearColor(0, 0, 0, 1) # print(b'OpenGL version: ' + glGetString(GL_VERSION)) # print(b'GLSL version: ' + glGetString(GL_SHADING_LANGUAGE_VERSION)) # print(b'Vendor: ' + glGetString(GL_VENDOR)) # print(b'Renderer: ' + glGetString(GL_RENDERER)) self.init() old_time = glfw.get_time() try: while not glfw.window_should_close(self.window): glfw.poll_events() if any(( ( glfw.get_key(self.window, glfw.KEY_LEFT_ALT) and \ glfw.get_key(self.window, glfw.KEY_F4) ), ( glfw.get_key(self.window, glfw.KEY_LEFT_CONTROL) and \ glfw.get_key(self.window, glfw.KEY_Q) ) )): glfw.set_window_should_close(self.window, True) now = glfw.get_time() self.update(float(now - old_time)) old_time = now self.render() glfw.swap_buffers(self.window) except KeyboardInterrupt: pass glfw.terminate()
def draw_ranita(): global posicion_triangulo glPushMatrix() glTranslatef(posicion_triangulo[0], posicion_triangulo[1], 0.0) glScalef(0.5, 0.5, 0.0) #Revisar colision if colisionando(): glfw.set_window_should_close(window) glColor3f(1, 0, 0) else: glColor3f(98 / 255, 198 / 255, 0 / 255) #RANA glTranslatef(0.75, 0.2, 0.0) glBegin(GL_QUADS) glVertex3f(-0.76, -0.11, 0.0) glVertex3f(-0.76, -0.15, 0.0) glVertex3f(-0.80, -0.15, 0.0) glVertex3f(-0.80, -0.11, 0.0) glVertex3f(-0.74, -0.25, 0.0) glVertex3f(-0.74, -0.15, 0.0) glVertex3f(-0.82, -0.15, 0.0) glVertex3f(-0.82, -0.25, 0.0) glVertex3f(-0.72, -0.18, 0.0) glVertex3f(-0.72, -0.15, 0.0) glVertex3f(-0.84, -0.15, 0.0) glVertex3f(-0.84, -0.18, 0.0) glVertex3f(-0.72, -0.22, 0.0) glVertex3f(-0.72, -0.25, 0.0) glVertex3f(-0.84, -0.25, 0.0) glVertex3f(-0.84, -0.22, 0.0) glVertex3f(-0.72, -0.27, 0.0) glVertex3f(-0.72, -0.22, 0.0) glVertex3f(-0.74, -0.22, 0.0) glVertex3f(-0.74, -0.27, 0.0) glVertex3f(-0.82, -0.27, 0.0) glVertex3f(-0.82, -0.22, 0.0) glVertex3f(-0.84, -0.22, 0.0) glVertex3f(-0.84, -0.27, 0.0) glVertex3f(-0.82, -0.13, 0.0) glVertex3f(-0.82, -0.15, 0.0) glVertex3f(-0.84, -0.15, 0.0) glVertex3f(-0.84, -0.13, 0.0) glVertex3f(-0.72, -0.13, 0.0) glVertex3f(-0.72, -0.15, 0.0) glVertex3f(-0.74, -0.15, 0.0) glVertex3f(-0.74, -0.13, 0.0) glEnd() glPopMatrix()
def alarm_handler(signal_number, stack_frame): """ Close the current GLFW window when called due to a SIGALRM. """ assert signal_number == signal.SIGALRM window = glfw.get_current_context() assert window is not None glfw.set_window_should_close(window, True)
def key_event(window,key,scancode,action,mods): if key == glfw.KEY_ESCAPE and action == glfw.PRESS: glfw.set_window_should_close(window, True) if key >= 0 and key < 1024: if action == glfw.PRESS: keys[key] = True elif action == glfw.RELEASE: keys[key] = False
def key(window, key, scancode, action, mods): # Check for keypress if action != 1: return # TODO: Replace with pause menu if key == glfw.KEY_ESCAPE and action == glfw.PRESS: glfw.set_window_should_close(window, True) return items = config.parser.items("Controls") key_map = {} for action in actions: for item in items: if item[0] == action[0]: key_chars = item[1].split(",") for char in key_chars: if char.startswith("NP_"): if char == "NP_7": keys = [375, 331] elif char == "NP_8": keys = [377, 332] elif char == "NP_9": keys = [380, 333] elif char == "NP_4": keys = [376, 328] elif char == "NP_5": keys = [383, 329] elif char == "NP_6": keys = [378, 330] elif char == "NP_1": keys = [382, 325] elif char == "NP_2": keys = [379, 326] elif char == "NP_3": keys = [382, 327] else: keys = [ord(char)] for key_code in keys: key_map[key_code] = action[1] if key in key_map: # FIXME: "Z" does not work? key_map[key]()
def on_key(window, key, scancode, action, mods): global d_x global color if action == glfw.PRESS: # ESC to quit if key == glfw.KEY_ESCAPE: glfw.set_window_should_close(window,1) elif key == glfw.KEY_UP: d_x += 0.1 elif key == glfw.KEY_DOWN: d_x += -0.1 elif key == glfw.KEY_SPACE: color.red += color.blue color.blue = color.red - color.blue color.red = color.red - color.blue
def keyboard_event(self, key, scancode, action, mods): """ Args: key (int): The keyboard key that was pressed or released. scancode (int): The system-specific scancode of the key. action (int): glfw.PRESS, glfw.RELEASE or glfw.REPEAT. mods (int): Bit field describing which modifier keys were held down. """ if key == glfw.KEY_ESCAPE: print 'Escape pressed...' glfw.set_window_should_close(self.window, True) return # TODO: possibly use glfwSetInputMode here instead if action in (glfw.PRESS, glfw.REPEAT): self.pressed_keys.add(key) else: self.pressed_keys.remove(key)
def key_callback(window, key, scancode, action, mods): global vertices, to_redraw, debug, to_draw_line, line, edges, cutted_line, to_slice if action == glfw.PRESS: if key == glfw.KEY_ESCAPE: glfw.set_window_should_close(window, 1) return if key == glfw.KEY_S: cutted_line = [] to_slice = not to_slice # ))) to_redraw = True if key == glfw.KEY_L: to_draw_line = not to_draw_line if key == glfw.KEY_C: vertices = [] edges = [] line = [] cutted_line = [] to_draw_line = False to_redraw = True
def handleKeyEvent(self, window, key, scancode, action, mods): redisplay = True updated = True if key in (glfw.KEY_Q, glfw.KEY_ESCAPE) and action == glfw.PRESS: glfw.set_window_should_close(window, GL_TRUE) updated = False elif key == glfw.KEY_KP_1 and action == glfw.PRESS: self.camera.front() elif key == glfw.KEY_KP_2 and action != glfw.RELEASE: self.camera.rotate(0.0, -self.camera.rotationRate) elif key == glfw.KEY_KP_3 and action == glfw.PRESS: self.camera.side() elif key == glfw.KEY_KP_4 and action != glfw.RELEASE: self.camera.rotate(-self.camera.rotationRate, 0.0) elif key == glfw.KEY_KP_5 and action == glfw.PRESS: self.ortho = not self.ortho elif key == glfw.KEY_KP_6 and action != glfw.RELEASE: self.camera.rotate(self.camera.rotationRate, 0.0) elif key == glfw.KEY_KP_7 and action == glfw.PRESS: self.camera.top() elif key == glfw.KEY_KP_8 and action != glfw.RELEASE: self.camera.rotate(0.0, self.camera.rotationRate) elif key == glfw.KEY_KP_9 and action == glfw.PRESS: self.camera.rotate(math.pi, 0.0) elif key == glfw.KEY_KP_DECIMAL and action == glfw.PRESS: self.camera.reset() elif key == glfw.KEY_KP_SUBTRACT and action == glfw.PRESS: self.camera.zoomOut() elif key == glfw.KEY_KP_ADD and action == glfw.PRESS: self.camera.zoomIn() elif key == glfw.KEY_Z and action == glfw.PRESS: self.wireframe = not self.wireframe updated = False else: redisplay = False updated = False if updated: self.updateMatrix(self.viewport) if redisplay: self.redisplay = True
def KillProgram(): global window glfw.set_window_should_close(window, GL_TRUE)
def key_cb(self, window, key, scancode, action, mods): if key == glfw.KEY_ESCAPE: glfw.set_window_should_close(window, True) for cb in self.key_callbacks: cb(window, key, scancode, action, mods)
def on_key(window, key, scancode, action, mods): if( key == glfw.KEY_ESCAPE and action == glfw.PRESS ): glfw.set_window_should_close( window, True )
def on_key(self, window, key, scancode, action, mods): if key == glfw.KEY_ESCAPE and action == glfw.PRESS: glfw.set_window_should_close(window, 1)
def close(self): """ Suggest to glfw the window should be closed soon """ glfw.set_window_should_close(self.window, True)
def key_callback(self, window, key, scancode, action, mods): print "key_callback" if key == glfw.KEY_ESCAPE and action == glfw.PRESS: glfw.set_window_should_close(self.window, True)
def key_callback(self, window, key, scancode, action, mods): "press ESCAPE to quit the application" if key == glfw.KEY_ESCAPE and action == glfw.PRESS: glfw.set_window_should_close(self.window, True)
def key_cb(window, key, scancode, action, mode): if key == glfw.KEY_ESCAPE and action == glfw.PRESS: # print("quit now") glfw.set_window_should_close(window, True)