def run(self): while not glfw.window_should_close(self.window): if self.redisplay: self.redisplay = False self.drawScene() glfw.wait_events() glfw.terminate()
def main(): global val_degree global val_translate global val_switch global val_scale global val_T if not glfw.init(): return window = glfw.create_window(480, 480, "CG_weekly_practice_04_2016024866", None, None) if not window: glfw.terminate() return glfw.make_context_current(window) glfw.swap_interval(1) while not glfw.window_should_close(window): glfw.wait_events() #t=glfw.get_time() #rotation part #th=np.radians(-60) glfw.set_key_callback(window, key_callback) # R=np.identity(3) # R[:2,:2 ] = [[np.cos(round(val_degree*np.pi/180,2)), -np.sin(round(val_degree*np.pi/180,2))], # [np.sin(round(val_degree*np.pi/180,2)), np.cos(round(val_degree*np.pi/180,2))]] # #translate part # T=np.identity(3) # T[:3,2] = [val_translate,0.,0.] # #scale part # S=np.identity(3) # S[:2,:2] =[[val_scale,0], # [0,1]] render(val_T) glfw.swap_buffers(window) glfw.terminate()
def wait_keys(self): self._event_buffer.clear() while not self._event_buffer: glfw.wait_events() return self.get_keys()
def run(self): glfw.make_context_current(self._wnd) self._ctx = ModernGL.create_context() self.initialize(self._ctx) while not glfw.window_should_close(self._wnd): width, height = self.size() self._ctx.viewport = (0, 0, width, height) self.render(self._ctx) glfw.swap_buffers(self._wnd) glfw.wait_events()
def main(): global val_mode if not glfw.init(): return window = glfw.create_window(480, 480, "CG_weekly_practice_03-1_2016024866", None, None) if not window: glfw.terminate() return glfw.make_context_current(window) glfw.swap_interval(1) while not glfw.window_should_close(window): glfw.wait_events() glfw.set_key_callback(window, key_callback) #key evenet handler render() glfw.swap_buffers(window) glfw.terminate()
def run(self): assert self.window is not None while not glfw.window_should_close(self.window): if self.animating: glfw.poll_events() else: glfw.wait_events() self.update() if self.need_render or self.animating: self._render() self.destroy() glfw.destroy_window(self.window) glfw.terminate()
def run(self): prctl.set_name("Plot rendering thread") while True: glfw.wait_events() glfw.poll_events() with self.l: for w in self.windows: glfw.make_context_current(w.window) if glfw.window_should_close(w.window): self.close(w) else: w.presentData() #for i in range(len(self.windows)): # if glfw.window_should_close(self.windows[i].window): # glfw.destroy_window(self.windows[i].window) # self.windows.pop(i) # else: # self.windows[i].presentData() if len(self.windows) == 0: print("No plots left, stopping thread") break
def wait_events(self, timeout=None): if timeout is None: glfw.wait_events() else: glfw.wait_events_timeout(timeout)
else: dragging = False dragging = False if not glfw.init(): raise RuntimeError('Could not initialize GLFW3') glfw.window_hint(glfw.DOUBLEBUFFER, glfw.FALSE) window = glfw.create_window(W_INIT, H_INIT, 'WalkThrough_06', None, None) if not window: glfw.terminate() raise RuntimeError('Could not create an window') glfw.set_window_size_callback(window, resize) glfw.set_window_refresh_callback(window, window_refresh) glfw.set_cursor_pos_callback(window, cursor_pos) glfw.set_mouse_button_callback(window, mouse_button) glfw.make_context_current(window) gen_cube() scene() init() while not glfw.window_should_close(window): glfw.wait_events() glfw.terminate()
def flutter_window_loop(flutter_window): while not glfw.window_should_close(flutter_window): glfw.wait_events() """FlutterEngineShutdown""" glfw.destroy_window(flutter_window)
def main(): if not glfw.init(): return glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 4) glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 1) glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, True) glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE) glfw.window_hint(glfw.DOUBLEBUFFER, 0) glfw.window_hint(glfw.SAMPLES, 16) width = 1920 height = 1080 aspect = 1.0 * width / height window = glfw.create_window(width, height, "Mandelbrot", None, None) if not window: glfw.terminate() return glfw.make_context_current(window) # print(f"opengl version: {gl.glGetString(gl.GL_VERSION).decode('ascii')}") # print(f"opengl vendor: {gl.glGetString(gl.GL_VENDOR).decode('ascii')}") # print(f"opengl renderer: {gl.glGetString(gl.GL_RENDERER).decode('ascii')}") vertex_shader = make_shader(gl.GL_VERTEX_SHADER, vertex_shader_src) fragment_shader = make_shader(gl.GL_FRAGMENT_SHADER, fragment_shader_src) program = make_program([vertex_shader, fragment_shader]) vert_values = numpy.array([ -1, -1 * aspect, 0, 1, -1 * aspect, 0, -1, 1 * aspect, 0, -1, 1 * aspect, 0, 1, -1 * aspect, 0, 1, 1 * aspect, 0, ], dtype='float64') # creating vertex array vert_array = gl.glGenVertexArrays(1) gl.glBindVertexArray(vert_array) vert_buffer = gl.glGenBuffers(1) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, vert_buffer) gl.glBufferData(gl.GL_ARRAY_BUFFER, vert_values, gl.GL_STATIC_DRAW) gl.glClearColor(0, 0, 0, 0) gl.glClear(gl.GL_COLOR_BUFFER_BIT) gl.glUseProgram(program) # setup coordinate buffer gl.glEnableVertexAttribArray(0) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, vert_buffer) gl.glVertexAttribPointer(0, 3, gl.GL_DOUBLE, gl.GL_FALSE, 0, None) # setup uniforms for fragment shader transform_loc = gl.glGetUniformLocation(program, 'transform') max_iters_loc = gl.glGetUniformLocation(program, 'max_iters') # setup color buffer # gl.glEnableVertexAttribArray(1) # gl.glBindBuffer(gl.GL_ARRAY_BUFFER, color_buffer) # gl.glVertexAttribPointer(1, 3, gl.GL_FLOAT, gl.GL_FALSE, 0, None) state = { 'zoom': 1, 'pos_x': -0.7600189058857209, 'pos_y': 0.0799516080512771, 'max_iters': 100, } def char_callback(window, char): ch = chr(char) change = False if ch == '-': state['zoom'] *= 1.1 state['zoom'] = min(10, state['zoom']) change = True elif ch in ('+', '='): state['zoom'] *= 0.9 change = True elif ch == ']': state['max_iters'] *= 1.1 change = True elif ch == '[': state['max_iters'] *= 0.9 change = True if change: print('Current zoom:', state['zoom']) print('Current max_iters:', state['max_iters']) def key_callback(window, key, scancode, action, mods): change = False if action in (glfw.PRESS, glfw.REPEAT): if key == glfw.KEY_UP: state['pos_y'] += state['zoom'] * 0.02 change = True elif key == glfw.KEY_DOWN: state['pos_y'] -= state['zoom'] * 0.02 change = True elif key == glfw.KEY_RIGHT: state['pos_x'] += state['zoom'] * 0.02 change = True elif key == glfw.KEY_LEFT: state['pos_x'] -= state['zoom'] * 0.02 change = True if change: print('Current center:', state['pos_x'], state['pos_y']) glfw.set_char_callback(window, char_callback) glfw.set_key_callback(window, key_callback) time_before = glfw.get_time() print("use +/- to zoom in/out") print("use [/] to increase/decrease max_iters") print("use arrows to pan") while not glfw.window_should_close(window): zoom = state['zoom'] pos_x = state['pos_x'] pos_y = state['pos_y'] gl.glUniformMatrix3dv( transform_loc, 1, False, numpy.array( [aspect * zoom, 0, pos_x, 0, 1 * zoom, pos_y, 0, 0, 1 * zoom], dtype='float64')) gl.glUniform1i(max_iters_loc, int(state['max_iters'])) gl.glDrawArrays(gl.GL_TRIANGLES, 0, int(len(vert_values) / 3)) time = glfw.get_time() print("frame render time", time - time_before) time_before = time gl.glFlush() glfw.wait_events() glfw.terminate()
def events_loop(self): glfw.wait_events()