def draw_window(self, window, colour): window.switch_to() glClearColor(*colour) glClear(GL_COLOR_BUFFER_BIT) window.flip()
state = get_next_state(state) last_update = time.time() return (state, last_update, update_period) @window.event def on_key_press(symbol, modifiers): global speed_IO, pause_IO if symbol == key.SPACE: pause_IO = 1 - pause_IO elif symbol == key.MINUS: speed_IO = speed_IO / SPEED_MODIFIER_STEP elif symbol == key.EQUAL: speed_IO = speed_IO * SPEED_MODIFIER_STEP @window.event def on_mouse_press(x, y, button, modifiers): global point_buffer_IO if button == mouse.LEFT: point_buffer_IO.append([x, y]) while not window.has_exit: dt = clock.tick() (state, last_update, update_period) = updateIO(state, last_update, update_period) window.dispatch_events() window.clear() draw(state) window.flip()
def main(): screen_width = 800 screen_height = 600 window = pyglet.window.Window(screen_width, screen_height) cparams = TextureParam(wrap = GL_CLAMP) buf = FrameBuffer(screen_width, screen_height, Surface(Surface.SURF_COLOUR, gl_tgt=GL_TEXTURE_RECTANGLE_ARB, params=cparams), Surface(Surface.SURF_DEPTH, gl_tgt=GL_TEXTURE_RECTANGLE_ARB, gl_fmt=GL_DEPTH_COMPONENT32_ARB, is_texture=True, is_mipmapped=False, params=cparams)) buf.init() buf.attach() buf.unbind() alpha_buf = FrameBuffer(screen_width, screen_height, Surface(Surface.SURF_COLOUR, gl_tgt=GL_TEXTURE_RECTANGLE_ARB, params = cparams)) alpha_buf.init() alpha_buf.attach() alpha_buf.unbind() buf_subsampled = FrameBuffer(200, 150, Surface(Surface.SURF_COLOUR, gl_tgt=GL_TEXTURE_RECTANGLE_ARB, params=cparams), Surface(Surface.SURF_DEPTH, params=cparams)) buf_subsampled.init() buf_subsampled.attach() buf_subsampled.unbind() buf_subsampled2 = FrameBuffer(200, 150, Surface(Surface.SURF_COLOUR, gl_tgt=GL_TEXTURE_RECTANGLE_ARB, params=cparams), Surface(Surface.SURF_DEPTH, params=cparams)) buf_subsampled2.init() buf_subsampled2.attach() buf_subsampled2.unbind() object = cube_array_list() downsampler=DownsamplerRect() noise=gaussNoise(32) blur=GaussianRect3() pass1=RenderDOFPass1() pass2=RenderDOFPass2() r = 0 clk = clock.Clock(60) while not window.has_exit: clk.tick() window.dispatch_events() buf.bind() glViewport(0, 0, screen_width, screen_height) r += 1 if r > 360: r = 0 renderScene(r, object) buf.unbind() downsample(buf.colourBuffer(0), buf_subsampled, downsampler, noise) gaussianBlur(buf_subsampled.colourBuffer(0), buf_subsampled2, buf_subsampled, 0.0, 0.0, 200.0, 150.0, blur) renderDOF(buf, alpha_buf, buf_subsampled, pass1, pass2, noise) #fps.draw(window, clk) window.flip() buf = None buf_subsampled = None