Beispiel #1
0
    def __init__(self):
        app.Canvas.__init__(self)

        self.program = oogl.Program(VERT_SHADER, FRAG_SHADER)
        
        # Set uniform and attribute
        self.program['a_color']    = oogl.VertexBuffer(v_color)
        self.program['a_position'] = oogl.VertexBuffer(v_position)
        self.program['a_size']     = oogl.VertexBuffer(v_size)
    def init_gl(self):
        self.program = oogl.ShaderProgram(
            oogl.VertexShader(vertex_shader),
            oogl.FragmentShader(fragment_shader),
        )

        self.vbo = oogl.VertexBuffer(self.data)
Beispiel #3
0
    def __init__(self):
        app.Canvas.__init__(self)
        self.geometry = 0, 0, 400, 400

        self.program = oogl.ShaderProgram(oogl.VertexShader(VERT_CODE),
                                          oogl.FragmentShader(FRAG_CODE))

        # Set attributes
        self.program.attributes['a_position'] = oogl.VertexBuffer(positions)
        self.program.attributes['a_color'] = oogl.VertexBuffer(colors)

        self.init_transforms()

        self.timer = app.Timer(1.0 / 60)
        self.timer.connect(self.update_transforms)
        self.timer.start()
Beispiel #4
0
    def __init__(self):
        app.Canvas.__init__(self)

        # Create program
        self._program = oogl.Program(VERT_SHADER, FRAG_SHADER)

        # Set uniform and attribute
        self._program['u_color'] = 0.2, 1.0, 0.4, 1
        self._program['a_position'] = oogl.VertexBuffer(vPosition)
Beispiel #5
0
    def __init__(self, **kwargs):
        app.Canvas.__init__(self, **kwargs)
        self.geometry = 0, 0, 400, 400

        self.program = oogl.Program(VERT_CODE, FRAG_CODE)

        # Set attributes
        self.program['a_position'] = oogl.VertexBuffer(positions)
        self.program['a_texcoord'] = oogl.VertexBuffer(texcoords)

        self.program['u_texture'] = oogl.Texture2D(io.crate())

        # Handle transformations
        self.init_transforms()

        self.timer = app.Timer(1.0 / 60)
        self.timer.connect(self.update_transforms)
        self.timer.start()
Beispiel #6
0
 def on_paint(self, event):
     # Simulate the case where x values on the GPU are between N-1, N+1
     # with N very large. Translation back to [-1,1] happens on the GPU
     self._position[:, 0] = np.arange(-1, 1, self.dt) + self.translation
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     with self._program as prog:
         prog['a_position'] = oogl.VertexBuffer(self._position)
         prog['u_translation'] = self.translation
         prog['u_scale'] = self.scale
         prog.draw_arrays(gl.GL_LINE_STRIP)
Beispiel #7
0
    def __init__(self):
        app.Canvas.__init__(self)
        
        # Time
        self._t = time.time()
        self._pos = 0.0, 0.0
        self._button = None
        
        # Create program
        self.program = oogl.Program(VERT_SHADER, FRAG_SHADER)
    
        # Create vertex buffers
        self.vbo_position = oogl.VertexBuffer(particles['position'])
        self.vbo_color = oogl.VertexBuffer(particles['color'])
        self.vbo_size = oogl.VertexBuffer(particles['size'])

        # Bind vertex buffers
        self.program['color'] = self.vbo_color
        self.program['size'] = self.vbo_size
        self.program['position'] = self.vbo_position
Beispiel #8
0
    def __init__(self):
        app.Canvas.__init__(self)
        self.size = 560, 420

        # Create texture to render to
        self._rendertex = oogl.Texture2D()

        # Create FBO, attach the color buffer and depth buffer
        self._fbo = oogl.FrameBuffer(self._rendertex, oogl.RenderBuffer())

        # Create program to render a shape
        self._program1 = oogl.Program(oogl.VertexShader(VERT_SHADER1),
                                      oogl.FragmentShader(FRAG_SHADER1))
        self._program1['u_color'] = 0.9, 1.0, 0.4, 1
        self._program1['a_position'] = oogl.VertexBuffer(vPosition)

        # Create program to render FBO result
        self._program2 = oogl.Program(oogl.VertexShader(VERT_SHADER2),
                                      oogl.FragmentShader(FRAG_SHADER2))
        self._program2['a_position'] = oogl.VertexBuffer(vPosition)
        self._program2['a_texcoord'] = oogl.VertexBuffer(vTexcoord)
        self._program2['u_texture1'] = self._rendertex
Beispiel #9
0
 def __init__(self):
     app.Canvas.__init__(self)
     self.position = (200, 100)
     self.size = (800, 500)
     self._program = oogl.Program(VERT_SHADER, FRAG_SHADER)
     self.dt = 1./1000
     self.n = 2000
     self._position = np.zeros((self.n, 2))
     self._position[:, 1] = .25 * np.random.randn(self.n)
     prog = self._program
     prog['a_position'] = oogl.VertexBuffer(self._position)
     prog['u_translation'] = self.translation
     prog['u_scale'] = self.scale
Beispiel #10
0
    def __init__(self):
        app.Canvas.__init__(self)

        self.program = oogl.Program(VERT_SHADER, FRAG_SHADER)

        # Set uniform and attribute
        self.program['a_id'] = oogl.VertexBuffer(a_id)
        self.program['a_position'] = oogl.VertexBuffer(a_position)

        self.view = np.eye(4, dtype=np.float32)
        self.model = np.eye(4, dtype=np.float32)
        self.projection = np.eye(4, dtype=np.float32)

        self.translate = 5
        translate(self.view, 0, 0, -self.translate)
        self.program['u_model'] = self.model
        self.program['u_view'] = self.view

        self.theta = 0
        self.phi = 0

        self.timer = app.Timer(1.0 / 60)
        self.timer.connect(self.on_timer)
Beispiel #11
0
    def __init__(self):
        app.Canvas.__init__(self)

        # Create program
        self._program = oogl.Program(VERT_SHADER, FRAG_SHADER)

        # Create vertex buffer
        self._vbo = oogl.VertexBuffer(vertex_data)

        # Set uniforms, samplers, attributes
        # We create one VBO with all vertex data (array of structures)
        # and create two views from it for the attributes.
        self._program['texture1'] = oogl.Texture2D(im1)
        self._program.set_vars(self._vbo)  # This does:
Beispiel #12
0
    def on_resize(self, event):
        width, height = event.size
        gl.glViewport(0, 0, width, height)
        self.projection = ortho( 0, width, 0, height, -100, 100 )
        self.program['u_projection'] = self.projection

        # Compute thje new size of the quad 
        r = width/float(height)
        R = W/float(H)
        if r < R:
            w,h = width, width/R
            x,y = 0, int((height-h)/2)
        else:
            w,h = height*R, height
            x,y = int((width-w)/2), 0
        data['a_position'] = np.array([[x, y], [x+w, y], [x, y+h], [x+w, y+h]])
        self.program.set_vars(oogl.VertexBuffer(data))
Beispiel #13
0
    def __init__(self):
        app.Canvas.__init__(self)

        self.geometry = 0, 0, 400, 400

        # Create program
        self._program = oogl.ShaderProgram(oogl.VertexShader(VERT_SHADER),
                                           oogl.FragmentShader(FRAG_SHADER))

        # Create vbo
        self._vbo = oogl.VertexBuffer(vertex_data)

        # Set uniforms, samplers, attributes
        self._program.attributes.update(self._vbo)
        self._program.uniforms['s_texture'] = oogl.Texture2D(im1)

        # Create first explosion
        self._new_explosion()
Beispiel #14
0
    def __init__(self):
        app.Canvas.__init__(self)
        self.size = W*5,H*5

        self.program = oogl.Program(VERT_SHADER, FRAG_SHADER)
        self.texture = oogl.Texture2D(I)
        self.texture.set_filter(gl.GL_NEAREST, gl.GL_NEAREST)
        
        self.program['u_texture'] = self.texture
        self.program.set_vars(oogl.VertexBuffer(data))

        self.view = np.eye(4,dtype=np.float32)
        self.model = np.eye(4,dtype=np.float32)
        self.projection = np.eye(4,dtype=np.float32)

        self.program['u_model'] = self.model
        self.program['u_view'] = self.view
        self.projection = ortho(0, W, 0, H, -1, 1)
        self.program['u_projection'] = self.projection
Beispiel #15
0
    def __init__(self):
        app.Canvas.__init__(self)
        self.size = 800, 600

        self.vertices, self.filled, self.outline = cube()

        self.program = oogl.Program(vert, frag)
        self.program.set_vars(oogl.VertexBuffer(self.vertices))

        self.view = np.eye(4, dtype=np.float32)
        self.model = np.eye(4, dtype=np.float32)
        self.projection = np.eye(4, dtype=np.float32)

        translate(self.view, 0, 0, -5)
        self.program['u_model'] = self.model
        self.program['u_view'] = self.view

        self.theta = 0
        self.phi = 0

        self._timer = app.Timer(1.0 / 60)
        self._timer.connect(self.on_timer)
        self._timer.start()
Beispiel #16
0
 def __init__(self):
     app.Canvas.__init__(self)
     
     # Create program
     self._program = oogl.Program( VERT_SHADER, FRAG_SHADER)
     
     # Creat FBO
     self._fbo = oogl.FrameBuffer()
     self._fbo.attach_depth(oogl.RenderBuffer(im1.shape))
     
     # Create vbo
     self._vbo = oogl.VertexBuffer(vertex_data)
     
     # Create textures 
     self._tex1 = oogl.Texture2D(im1)
     self._tex2 = oogl.Texture2D(im1.shape)
     for tex in (self._tex1, self._tex2):
         tex.set_filter('NEAREST', 'NEAREST')
     
     
     # Set uniforms and attributes
     self._program.set_vars(self._vbo)
     self._program['u_texsize'] = im1.shape[1], im1.shape[0]
Beispiel #17
0
 def update_buffers(self):
     self.width_max = self.data['width'].max()
     self.vbo = oogl.VertexBuffer(self.data)