Example #1
0
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 on_draw():
        window.clear()
        with nested(Projection(0, 0, window.width, window.height, far=1000.0),
                    Matrix, Lighting):
            glTranslatef(0, 0, -40)

            with Matrix:
                glMultMatrixf(box.matrix)
                cube(size=(10, 10, 10), color=(0.5, 0.5, 0.5, 1.0))

        fps.draw()
        description.draw()
Example #3
0
    def on_draw():
        window.clear()
        with nested(Projection(0, 0, window.width, window.height, far=1000.0),
                    Matrix, Lighting):
            glTranslatef(0, 0, -500)
            glRotatef(tilt * 0.3, 1.0, 0, 0)
            glRotatef(rotate * 0.3, 0.0, 1.0, 0)

            for body in bodies:
                with Matrix:
                    glMultMatrixf(body.matrix)
                    cube(size=body.size, color=(0.5, 0.5, 0.5, 1.0))

        fps.draw()
        description.draw()
Example #4
0
 def on_draw():
     with Projection(0,
                     0,
                     window.width,
                     window.height,
                     fov=65,
                     near=0.1,
                     far=20000):
         window.clear()
         glPushMatrix()
         glTranslatef(0, 0, -5)
         glRotatef(15, 1.0, 0.0, 0.0)
         glRotatef(rotation, 0.0, 1.0, 0.0)
         mesh.draw(GL_TRIANGLES)
         glPopMatrix()
Example #5
0
    def on_draw():
        window.clear()
        with nested(Projection(0, 0, window.width, window.height, far=1000.0), Matrix, Lighting):
            glTranslatef(0, 15, -60)
            glRotatef(tilt*0.3, 1.0, 0, 0)
            glRotatef(rotate*0.3, 0.0, 1.0, 0)

            for box in boxes:
                with Matrix:
                    glMultMatrixf(box.matrix)
                    cube(size=box_size, color=(0.2, 0.2, 0.2, 1.0))

            with Matrix:
                glMultMatrixf(ground.matrix)
                cube(size=ground_size, color=(0.2, 0.7, 0.2, 1.0))

        fps.draw()
        description.draw()
Example #6
0
from __future__ import with_statement
from contextlib import nested

import pyglet
from gletools import ShaderProgram, FragmentShader, Texture, Framebuffer, Projection, Screen
from gletools.gl import *

from random import random
from util import quad, Processor, ChangeValue
from gaussian import Gaussian

window = pyglet.window.Window()
projection = Projection(0, 0, window.width, window.height)
noise = ShaderProgram(
    FragmentShader.open('shaders/noise.frag'),
    seed=0.0,
)
width, height = 64, 64
noise_texture = Texture(width, height, format=GL_RGBA32F)
noise_processor = Processor(noise_texture)
texture = Texture(64, 64, format=GL_RGBA32F)
processor = Processor(texture)

noise_processor.filter(noise_texture, noise)
processor.copy(noise_texture, texture)
gaussian = Gaussian(processor)
gaussian.filter(texture, 2)

rotation = ChangeValue()

Example #7
0
from __future__ import with_statement
from contextlib import nested

import pyglet
from gletools import (
    ShaderProgram, FragmentShader, VertexShader, Depthbuffer,
    Texture, Projection, UniformArray, Lighting, Color
)
from gletools.gl import *
from util import Mesh, Processor, Kernel, offsets, gl_init
from gaussian import Gaussian

### setup ###

window = pyglet.window.Window()
projection = Projection(0, 0, window.width, window.height, near=18, far=50)
texture = Texture(window.width, window.height, GL_RGBA32F)
bunny = Mesh('meshes/brain')
processor = Processor(texture)

### Shaders and helpers ###

depth = ShaderProgram(
    VertexShader.open('shaders/normal.vert'),
    FragmentShader.open('shaders/depth.frag'),
)

average = ShaderProgram(
    VertexShader.open('shaders/normal.vert'),
    FragmentShader.open('shaders/convolution.frag'),
    kernel_size = 3*3,
Example #8
0
from __future__ import with_statement

import pyglet
from gletools import Projection, Lighting, Color, VertexObject
from gletools.gl import *
from util import Mesh, gl_init, ChangeValue, nested

window = pyglet.window.Window()
projection = Projection(0, 0, window.width, window.height, near=0.1, far=10)
angle = ChangeValue()

vbo = VertexObject(indices=[0, 1, 2],
                   v4f=[
                       0.0,
                       -1.0,
                       0.0,
                       1.0,
                       1.0,
                       0.0,
                       0.0,
                       1.0,
                       -1.0,
                       0.0,
                       0.0,
                       1.0,
                   ],
                   n3f=[
                       0.0,
                       0.0,
                       -1.0,
                       0.0,
Example #9
0
from __future__ import with_statement

import pyglet
from gletools import Projection, Lighting, Color, VertexObject
from gletools.gl import *
from util import Mesh, gl_init, ChangeValue, nested
from random import random

if __name__ == '__main__':
    window = pyglet.window.Window(vsync=False)
    projection = Projection(0,
                            0,
                            window.width,
                            window.height,
                            near=100,
                            far=700)
    angle = ChangeValue()
    bunny = Mesh('meshes/bunny')
    positions = [(random() * 300 - 150, random() * 300 - 150,
                  random() * 300 - 150) for _ in range(500)]

    fps = pyglet.clock.ClockDisplay()

    @window.event
    def on_draw():
        window.clear()

        with nested(projection, Lighting, bunny.vbo):
            glClearColor(0.0, 0.0, 0.0, 0.0)
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)