Example #1
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.u_size = width/512.0
     self.program['u_projection'] = self.projection
     self.program['u_size'] = self.u_size
Example #2
0
def paint():

    n = 100
    data = np.hstack(
        (.2 * np.random.randn(n, 2), np.random.rand(n, 4))).astype(np.float32)

    vs = compile_shader(VS, gl.GL_VERTEX_SHADER)
    fs = compile_shader(FS, gl.GL_FRAGMENT_SHADER)
    shaders_program = link_shader_program(vs, fs)

    buffer = gl.glGenBuffers(1)
    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer)
    gl.glBufferData(gl.GL_ARRAY_BUFFER, data, gl.GL_STATIC_DRAW)

    l = gl.glGetAttribLocation(shaders_program, "position")
    gl.glVertexAttribPointer(l, 2, gl.GL_FLOAT, gl.GL_FALSE, 0, None)
    gl.glEnableVertexAttribArray(l)

    lc = gl.glGetAttribLocation(shaders_program, "color")
    gl.glVertexAttribPointer(lc, 4, gl.GL_FLOAT, gl.GL_FALSE, 2 * 4, None)
    gl.glEnableVertexAttribArray(lc)

    gl.glUseProgram(shaders_program)

    gl.glViewport(0, 0, 500, 500)
    gl.glClearColor(0., 0., 0., 1.)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

    gl.glEnable(gl.GL_BLEND)
    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE)

    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer)

    gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, data.shape[0])
Example #3
0
 def on_paint(self, event):
     
     # Set framebuffer input output
     self._program['u_texture'] = self._tex1
     self._fbo.attach_color(self._tex2)
     
     with self._fbo:
         with self._program as prog:
             # Init
             gl.glViewport(0, 0, im1.shape[1], im1.shape[0])
             gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
             # Draw
             prog.draw_arrays(gl.GL_TRIANGLE_STRIP)
     
     # Draw to the normal color buffer (i.e. the screen)
     self._program['u_texture'] = self._tex2
     with self._program as prog:
         # Init
         gl.glViewport(0, 0, self.size[0], self.size[1])
         gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
         # Draw
         prog.draw_arrays(gl.GL_TRIANGLE_STRIP)
     
     # Prepare for next round
     self._tex1, self._tex2 = self._tex2, self._tex1
     
     # Force redraw
     self.update()
Example #4
0
 def on_paint(self, event):
     
     # Set framebuffer input output
     self._program['u_texture'] = self._tex1
     self._fbo.attach_color(self._tex2)
     
     with self._fbo:
         # Init
         gl.glViewport(0, 0, im1.shape[1], im1.shape[0])
         gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
         # Draw
         self._program.draw(gl.GL_TRIANGLE_STRIP)
     
     # Draw to the normal color buffer (i.e. the screen)
     self._program['u_texture'] = self._tex2
     # Init
     gl.glViewport(0, 0, self.size[0], self.size[1])
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     # Draw
     self._program.draw(gl.GL_TRIANGLE_STRIP)
     
     # Prepare for next round
     self._tex1, self._tex2 = self._tex2, self._tex1
     
     # Force redraw
     self.update()
Example #5
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.u_size = width / 512.0
     self.program['u_projection'] = self.projection
     self.program['u_size'] = self.u_size
Example #6
0
 def on_paint(self, event):
     # Paint events are "manually" propagated to the viewport instances,
     # because we first want to set the glViewport for each one.
     
     # Prepare
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
     w1 = self.size[0] // 2
     w2 = self.size[0] - w1
     # Left
     gl.glViewport(0, 0, w1, self.size[1])
     self.left.on_paint()
     # Right
     gl.glViewport(w1, 0, w2, self.size[1])
     self.right.on_paint()
     
     # Invoke new draw
     self.update()
Example #7
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))
Example #8
0
 def on_paint(self, event):
     
     # Set viewport and clear buffer
     gl.glViewport(0, 0, *self.geometry[2:])
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     
     # Draw
     with self._program as prog:
         prog.uniforms['u_time'] = time.time() - self._starttime
         prog.draw_arrays(gl.GL_POINTS)
     
     # Swap buffers and invoke a new draw
     self.swap_buffers()
     self.update()
     
     # New explosion?
     if time.time() - self._starttime > 1.5:
         self._new_explosion()
Example #9
0
    def on_paint(self, event):

        # Set viewport and clear buffer
        gl.glViewport(0, 0, *self.geometry[2:])
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        # Draw
        with self._program as prog:
            prog.uniforms['u_time'] = time.time() - self._starttime
            prog.draw_arrays(gl.GL_POINTS)

        # Swap buffers and invoke a new draw
        self.swap_buffers()
        self.update()

        # New explosion?
        if time.time() - self._starttime > 1.5:
            self._new_explosion()
Example #10
0
def paint():
    
    n = 100
    data = np.hstack((
        .2 * np.random.randn(n, 2),
        np.random.rand(n, 4)
    )).astype(np.float32)
    
    vs = compile_shader(VS, gl.GL_VERTEX_SHADER)
    fs = compile_shader(FS, gl.GL_FRAGMENT_SHADER)
    shaders_program = link_shader_program(vs, fs)
    
    buffer = gl.glGenBuffers(1)
    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer)
    gl.glBufferData(gl.GL_ARRAY_BUFFER, data, gl.GL_STATIC_DRAW)
    
    
    l = gl.glGetAttribLocation(shaders_program, "position")
    gl.glVertexAttribPointer(l, 2, gl.GL_FLOAT, gl.GL_FALSE, 0, None)
    gl.glEnableVertexAttribArray(l);
    
    lc = gl.glGetAttribLocation(shaders_program, "color")
    gl.glVertexAttribPointer(lc, 4, gl.GL_FLOAT, gl.GL_FALSE, 2 * 4, None)
    gl.glEnableVertexAttribArray(lc);
    
    gl.glUseProgram(shaders_program)
    
    gl.glViewport(0, 0, 500, 500)
    gl.glClearColor(0., 0., 0., 1.)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
    
    gl.glEnable(gl.GL_BLEND)
    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE)

    
    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer)
    
    gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, data.shape[0])
Example #11
0
 def reshape(width, height):
     gl.glViewport(0, 0, width, height)
Example #12
0
 def on_resize(self, event):
     width, height = event.size
     gl.glViewport(0, 0, width, height)
Example #13
0
 def on_resize(self, event):
     width, height = event.size
     gl.glViewport(0, 0, width, height)
     self.projection = perspective( 45.0, width/float(height), 1.0, 1000.0 )
     self.program['u_projection'] = self.projection
Example #14
0
 def on_resize(self, ev):
     gl.glViewport(0, 0, *ev.size)
     self._view_transform_dirty = True
Example #15
0
 def on_resize(self, ev):
     gl.glViewport(0, 0, *ev.size)
     self._view_transform_dirty = True
Example #16
0
 def reshape(width,height):
     gl.glViewport(0, 0, width, height)
Example #17
0
 def on_resize(self, event):
     width, height = event.size
     gl.glViewport(0, 0, width, height)
     self.projection = perspective(45.0, width / float(height), 2.0, 10.0)
     self.program['u_projection'] = self.projection
Example #18
0
 def on_resize(self, event):
     w, h = event.size
     gl.glViewport(0, 0, w, h)
     self.projection = perspective(45.0, w / float(h), 2.0, 10.0)
Example #19
0
 def on_resize(self, event):
     w, h = event.size
     gl.glViewport(0, 0, w, h)
     self.projection = perspective( 45.0, w/float(h), 2.0, 10.0 )