def main(): angle = ChangeValue() window = pyglet.window.Window(width=786, height=600, vsync=False) projection = Projection(0, 0, window.width, window.height, near=0.1, far=100) width, height = 128, 128 ripples = Ripples(width, height) height_texture = Texture(width*2, height*2, format=GL_RGBA32F) processor = Processor(height_texture) gaussian = Gaussian(processor) heightmap = Heightmap(width*2, height*2, scale=1.2) sun = Sun() def rain(delta): x = random.randint(0, ripples.width) y = random.randint(0, ripples.height) size = random.random() * 0.5 with nested(ripples.framebuffer, Color): glPointSize(size) glBegin(GL_POINTS) glColor4f(0.2, 0.2, 0.2, 1.0) glVertex3f(x, y, 0) glEnd() fps = pyglet.clock.ClockDisplay() pyglet.clock.schedule_interval(rain, 0.2) pyglet.clock.schedule(lambda delta: None) @window.event def on_draw(): window.clear() ripples.step() processor.copy(ripples.result, height_texture) gaussian.filter(height_texture, 2) heightmap.update_from(height_texture) with nested(projection, Color, sun): glColor3f(7/256.0, 121/256.0, 208/256.0) glPushMatrix() glTranslatef(0, 0, -1) glRotatef(10, 1, 0, 0) glRotatef(angle, 0.0, 1.0, 0.0) glTranslatef(-0.5, 0, -0.5) heightmap.draw() glPopMatrix() fps.draw() ripples.result.draw() heightmap.vertex_texture.draw(2*width, 0, scale=0.5) heightmap.normal_texture.draw(4*width, 0, scale=0.5) glEnable(GL_POINT_SMOOTH) glEnable(GL_LINE_SMOOTH) glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, GL_FALSE) glClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB, GL_FALSE) glClampColorARB(GL_CLAMP_READ_COLOR_ARB, GL_FALSE) gl_init(light=False) pyglet.app.run()
def simulate(delta): global angle angle += 10.0 * delta pyglet.clock.schedule_interval(simulate, 0.01) @window.event def on_draw(): window.clear() with nested(processor.renderto(texture), projection, Lighting, Color, depth): glClearColor(0.0,0.0,0.0,0.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glPushMatrix() glTranslatef(0, 0, -40) glRotatef(-65, 1, 0, 0) glRotatef(angle, 0.0, 0.0, 1.0) glRotatef(90, 1, 0, 0) glColor4f(0.5, 0.0, 0.0, 1.0) bunny.draw() glPopMatrix() processor.filter(texture, laplace) processor.filter(texture, invert) processor.blit(texture) if __name__ == '__main__': gl_init() pyglet.app.run()
texture = Texture.open('images/heightmap.png') heightmap = Heightmap(texture.width, texture.height) sun = Sun() @window.event def on_draw(): window.clear() heightmap.update_from(texture) with nested(projection, Color, sun): glColor3f(0.5, 0.5, 0.5) glPushMatrix() glTranslatef(0, 0, -1) glRotatef(20, 1, 0, 0) glRotatef(angle, 0.0, 1.0, 0.0) glTranslatef(-0.5, 0, -0.5) heightmap.draw() glPopMatrix() texture.draw(10, 10) heightmap.vertex_texture.draw(148, 10) heightmap.normal_texture.draw(286, 10) gl_init(light=False) if gl_info.have_extension('ARB_color_buffer_float'): glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, GL_FALSE) glClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB, GL_FALSE) glClampColorARB(GL_CLAMP_READ_COLOR_ARB, GL_FALSE) pyglet.app.run()
texture = Texture.open("images/heightmap.png") heightmap = Heightmap(texture.width, texture.height) sun = Sun() @window.event def on_draw(): window.clear() heightmap.update_from(texture) with nested(projection, Color, sun): glColor3f(0.5, 0.5, 0.5) glPushMatrix() glTranslatef(0, 0, -1) glRotatef(20, 1, 0, 0) glRotatef(angle, 0.0, 1.0, 0.0) glTranslatef(-0.5, 0, -0.5) heightmap.draw() glPopMatrix() texture.draw(10, 10) heightmap.vertex_texture.draw(148, 10) heightmap.normal_texture.draw(286, 10) gl_init(light=False) if gl_info.have_extension("ARB_color_buffer_float"): glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, GL_FALSE) glClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB, GL_FALSE) glClampColorARB(GL_CLAMP_READ_COLOR_ARB, GL_FALSE) pyglet.app.run()