window = app.Window(width=1024, height=1024, color=(.75, .75, .75, 1))


@window.event
def on_draw(dt):
    window.clear()
    teapot.draw(gl.GL_TRIANGLES, indices)


@window.event
def on_init():
    gl.glEnable(gl.GL_BLEND)
    gl.glEnable(gl.GL_DEPTH_TEST)


vertices, indices = primitives.teapot()
vertices["position"] *= 10
teapot = gloo.Program(teapot_vert, teapot_frag)
teapot.bind(vertices)
teapot['texture'] = data.checkerboard()

trackball = Trackball(Position("position"), znear=0.1, zfar=100.0, distance=50)
teapot['transform'] = trackball
trackball.theta = 40
trackball.phi = 135
trackball.zoom = 40

window.attach(teapot['transform'])
app.run()
Ejemplo n.º 2
0
    global vertices, indices, index
    if key == ord(' '):
        index = (index+1) % len(shapes)
        vertices, indices = shapes[index]
        program.bind(vertices)

index = 0
shapes = [ primitives.plane(1.5),
           primitives.cube(1.5),
           primitives.sphere(),
           primitives.cubesphere(),
           primitives.cylinder(),
           primitives.torus(),
           primitives.cone(),
           primitives.pyramid(),
           primitives.teapot() ]
vertices, indices = shapes[index]

program = gloo.Program(vertex, fragment)
program.bind(vertices)
view = np.eye(4, dtype=np.float32)
model = np.eye(4, dtype=np.float32)
projection = np.eye(4, dtype=np.float32)
glm.translate(view, 0, 0, -5)
program['model'] = model
program['view'] = view
program['normal'] = np.array(np.matrix(np.dot(view, model)).I.T)
program['texture'] = data.checkerboard()
program["light1_position"] = 3, 0, 0+5
program["light2_position"] = 0, 3, 0+5
program["light3_position"] = -3, -3, +5
Ejemplo n.º 3
0
    update()
    pass


@window.event
def on_character(character):
    global p
    print('Character entered (chracter: %s)' % character)
    if (character == ' '): p = 0
    if (character == 'p'): p = (p + 1) % 11
    obj['p'] = p


'''Models'''
# V, I = primitives.sphere()
V, I = primitives.teapot()
# V, I = primitives.cube()
# V, I = primitives.cubesphere()
# V, I = primitives.tube()
# V, I = data.get('teapot.obj')
path = '../models/bunny.obj'
# V, I = data.load(path)

obj = gloo.Program(vertex_shader, fragment_shader)
obj.bind(V)

trackball = Trackball(Position("position"))
obj['transform'] = trackball
trackball.theta, trackball.phi, trackball.zoom = 45, 45, 25  #40, 135, 25
'''lights'''
# obj["lightPositions[0]"] =  np.array((10,  10, -10))
Ejemplo n.º 4
0
    teapot.draw(gl.GL_TRIANGLES, indices)
    framebuffer.deactivate()
    
    # Compositing
    gl.glBlendFunc(gl.GL_ONE_MINUS_SRC_ALPHA, gl.GL_SRC_ALPHA)
    gl.glEnable(gl.GL_BLEND)
    post_process.draw(gl.GL_TRIANGLE_STRIP)



accumulation = np.zeros((window.height,window.width,4),np.float32).view(gloo.TextureFloat2D)
revealage    = np.zeros((window.height,window.width),np.float32).view(gloo.TextureFloat2D)
framebuffer  = gloo.FrameBuffer(color=[accumulation,revealage])


vertices, indices = primitives.teapot()
vertices["position"] *= 10
teapot = gloo.Program(teapot_vert, teapot_frag)
teapot.bind(vertices)
teapot['texture'] = data.checkerboard()

# Post composition
post_process = gloo.Program(post_process_vert, post_process_frag)
post_process['tex_accumulation'] = accumulation
post_process['tex_revealage'] = revealage
post_process['position']  = [(-1,-1), (-1,1), (1,-1), (1,1)]

trackball = Trackball(Position("position"), znear=0.1, zfar=100.0, distance=50)
teapot['transform'] = trackball
trackball.theta = 40
trackball.phi = 45