示例#1
0
 def on_paint(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     with self.program as prog:
         I[...] = np.random.uniform(0,1,(W,H)).astype(np.float32)
         self.texture.set_data(I)
         prog.draw_arrays(gl.GL_TRIANGLE_STRIP)
     self.update()
示例#2
0
 def on_paint(self, event):
     
     # Clear
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     
     # Draw shape with texture, nested context
     self._program.draw(gl.GL_TRIANGLE_STRIP)
示例#3
0
    def on_paint(self, event):
        
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        

        # Swap buffers
        self.swap_buffers()
示例#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:
         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()
示例#5
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])
示例#6
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()
示例#7
0
    def on_paint(self, event):

        # Technically, we would only need to set u_time on every draw,
        # because the program is enabled at the beginning and never disabled.
        # In vispy, the program is re-enabled at each draw though and we
        # want to keep the code similar.

        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        # Activate program  and texture
        gl.glUseProgram(self._prog_handle)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self._tex_handle)

        # Update VBO
        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._vbo_handle)
        gl.glBufferData(gl.GL_ARRAY_BUFFER, vertex_data.nbytes, vertex_data,
                        gl.GL_DYNAMIC_DRAW)

        # Set attributes (again, the loc can be cached)
        loc = gl.glGetAttribLocation(self._prog_handle,
                                     'a_lifetime'.encode('utf-8'))
        gl.glEnableVertexAttribArray(loc)
        gl.glVertexAttribPointer(loc, 1, gl.GL_FLOAT, False, 7 * 4,
                                 ctypes.c_voidp(0))
        #
        loc = gl.glGetAttribLocation(self._prog_handle,
                                     'a_startPosition'.encode('utf-8'))
        gl.glEnableVertexAttribArray(loc)
        gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, 7 * 4,
                                 ctypes.c_voidp(1 * 4))
        #
        loc = gl.glGetAttribLocation(self._prog_handle,
                                     'a_endPosition'.encode('utf-8'))
        gl.glEnableVertexAttribArray(loc)
        gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, 7 * 4,
                                 ctypes.c_voidp(4 * 4))
        #
        loc = gl.glGetUniformLocation(self._prog_handle,
                                      'u_color'.encode('utf-8'))
        gl.glUniform4f(loc, *self._color)

        # Set unforms
        loc = gl.glGetUniformLocation(self._prog_handle,
                                      'u_time'.encode('utf-8'))
        gl.glUniform1f(loc, time.time() - self._starttime)
        #
        loc = gl.glGetUniformLocation(self._prog_handle,
                                      'u_centerPosition'.encode('utf-8'))
        gl.glUniform3f(loc, *self._centerpos)

        # Draw
        gl.glDrawArrays(gl.GL_POINTS, 0, N)

        # New explosion?
        if time.time() - self._starttime > 1.5:
            self._new_explosion()

        # Redraw as fast as we can
        self.update()
示例#8
0
    def on_paint(self, event):

        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        with self.program as prog:
            prog.draw_elements(gl.GL_TRIANGLES, faces)

        # Swap buffers
        self.swap_buffers()
示例#9
0
 def on_paint(self, event):
     
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     
     with self.program as prog:
         prog.draw_elements(gl.GL_TRIANGLES, faces_buffer)
     
     # Swap buffers
     self.swap_buffers()
示例#10
0
    def on_paint(self, ev):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        for visual in self.visuals:
            #view_transform = transforms.STTransform(scale=(self.zoom, self.zoom), translate=self.pan)
            view_transform = self.view_transform()
            visual.transforms = [view_transform] + visual.my_transforms

            visual.draw()
        self.swap_buffers()
示例#11
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)
示例#12
0
    def on_paint(self, ev):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        for visual in self.visuals:
            #view_transform = transforms.STTransform(scale=(self.zoom, self.zoom), translate=self.pan)
            view_transform = self.view_transform()
            visual.transforms = [view_transform] + visual.my_transforms
                
            visual.draw()
        self.swap_buffers()
示例#13
0
文件: boids.py 项目: tobyhijzen/vispy
    def on_paint(self, event):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        
        # Draw
        self.program.draw(gl.GL_POINTS)
        
        # Next iteration
        self._t = self.iteration(time.time() - self._t)

        # Invoke a new draw
        self.update()
示例#14
0
文件: boids.py 项目: joe311/vispy
    def on_paint(self, event):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        
        # Draw
        with self.program as prog:
            prog.draw_arrays(gl.GL_POINTS)
        
        # Next iteration
        self._t = self.iteration(time.time() - self._t)

        # Invoke a new draw
        self.update()
示例#15
0
def on_paint(event):
    global t, t0, frames
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        
    t = time.time()
    frames = frames + 1
    elapsed = (t-t0) # seconds
    if elapsed > 2.5:
        print( "FPS : %.2f (%d frames in %.2f second)"
               % (frames/elapsed, frames, elapsed))
        t0, frames = t,0
    canvas.update()
示例#16
0
文件: atom.py 项目: tobyhijzen/vispy
    def on_paint(self, event):
        global T,dT,p,n
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        T += dT
        self.index = (self.index+1)%p
        data['a_position'][self.index::p,0] = np.cos(T)
        data['a_position'][self.index::p,1] = .5*np.sin(T)
        data['a_color'][:,3] -= 1.0/p
        data['a_color'][self.index::p,3] = 1

        self.program.draw(gl.GL_POINTS)
示例#17
0
    def on_paint(self, event):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        
        # Draw
        self.program['position'] = VertexBuffer(particles['position'], client=True)
        self.program.draw(gl.GL_POINTS)
        
        # Next iteration
        self._t = self.iteration(time.time() - self._t)

        # Invoke a new draw
        self.update()
示例#18
0
    def on_paint(self, event):
        global T, dT, p, n
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        T += dT
        self.index = (self.index + 1) % p
        data['a_position'][self.index::p, 0] = np.cos(T)
        data['a_position'][self.index::p, 1] = .5 * np.sin(T)
        data['a_color'][:, 3] -= 1.0 / p
        data['a_color'][self.index::p, 3] = 1

        with self.program as prog:
            prog.draw_arrays(gl.GL_POINTS)
示例#19
0
    def on_paint(self, event):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        # Draw
        with self.program as prog:
            self.program["position"] = ClientVertexBuffer(particles["position"])
            prog.draw_arrays(gl.GL_POINTS)

        # Next iteration
        self._t = self.iteration(time.time() - self._t)

        # Invoke a new draw
        self.update()
示例#20
0
 def on_paint(self, event):
     
     # Clear
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     
     # Draw
     self._program['sizeFactor'] = 0.5 + np.sin(time.time()*3)*0.2
     
     # Draw (pick one!)
     #self._program.draw(gl.GL_TRIANGLE_STRIP)
     self._program.draw(gl.GL_TRIANGLES, indices_buffer)
     #self._program.draw(gl.GL_TRIANGLES, client_indices_buffer)  # Not recommended
     
     self.update()
示例#21
0
    def on_paint(self, event):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        # Draw
        with self.program as prog:
            self.program['position'] = ClientVertexBuffer(
                particles['position'])
            prog.draw_arrays(gl.GL_POINTS)

        # Next iteration
        self._t = self.iteration(time.time() - self._t)

        # Invoke a new draw
        self.update()
示例#22
0
 def on_paint(self, event):
     
     # Technically, we would only need to set u_time on every draw,
     # because the program is enabled at the beginning and never disabled.
     # In vispy, the program is re-enabled at each draw though and we
     # want to keep the code similar.
     
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     
     # Activate program  and texture
     gl.glUseProgram(self._prog_handle)
     gl.glBindTexture(gl.GL_TEXTURE_2D, self._tex_handle)
     
     # Update VBO
     gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._vbo_handle)
     gl.glBufferData(gl.GL_ARRAY_BUFFER, vertex_data.nbytes, vertex_data, gl.GL_DYNAMIC_DRAW)
     
     # Set attributes (again, the loc can be cached)
     loc = gl.glGetAttribLocation(self._prog_handle, 'a_lifetime'.encode('utf-8'))
     gl.glEnableVertexAttribArray(loc)
     gl.glVertexAttribPointer(loc, 1, gl.GL_FLOAT, False, 7*4, ctypes.c_voidp(0))
     #
     loc = gl.glGetAttribLocation(self._prog_handle, 'a_startPosition'.encode('utf-8'))
     gl.glEnableVertexAttribArray(loc)
     gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, 7*4, ctypes.c_voidp(1*4))
     #
     loc = gl.glGetAttribLocation(self._prog_handle, 'a_endPosition'.encode('utf-8'))
     gl.glEnableVertexAttribArray(loc)
     gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, 7*4, ctypes.c_voidp(4*4))
     #
     loc = gl.glGetUniformLocation(self._prog_handle, 'u_color'.encode('utf-8'))
     gl.glUniform4f(loc, *self._color)
     
     # Set unforms
     loc = gl.glGetUniformLocation(self._prog_handle, 'u_time'.encode('utf-8'))
     gl.glUniform1f(loc, time.time()-self._starttime)
     #
     loc = gl.glGetUniformLocation(self._prog_handle, 'u_centerPosition'.encode('utf-8'))
     gl.glUniform3f(loc, *self._centerpos)
     
     # Draw
     gl.glDrawArrays(gl.GL_POINTS, 0, N)
     
     # New explosion?
     if time.time() - self._starttime > 1.5:
         self._new_explosion()
         
     # Redraw as fast as we can
     self.update()
示例#23
0
 def on_paint(self, event):
     
     # Clear
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     
     # Draw
     self._program['u_time'] = time.time() - self._starttime
     self._program.draw(gl.GL_POINTS)
     
     # Invoke a new draw
     self.update()
     
     # New explosion?
     if time.time() - self._starttime > 1.5:
         self._new_explosion()
示例#24
0
    def on_paint(self, event):

        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        # Activate program  and texture
        gl.glUseProgram(self._prog_handle)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self._tex_handle)

        # Set attributes (again, the loc can be cached)
        loc = gl.glGetAttribLocation(self._prog_handle,
                                     'a_position'.encode('utf-8'))
        gl.glEnableVertexAttribArray(loc)
        if use_buffers:
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._positions_handle)
            gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, 0, None)
        else:
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0)  # 0 means do not use buffer
            gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, 0, positions)
        #
        loc = gl.glGetAttribLocation(self._prog_handle,
                                     'a_texcoord'.encode('utf-8'))
        gl.glEnableVertexAttribArray(loc)
        if use_buffers:
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._texcoords_handle)
            gl.glVertexAttribPointer(loc, 2, gl.GL_FLOAT, False, 0, None)
        else:
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0)  # 0 means do not use buffer
            gl.glVertexAttribPointer(loc, 2, gl.GL_FLOAT, False, 0, texcoords)

        # Set uniforms (note that you could cache the locations)
        loc = gl.glGetUniformLocation(self._prog_handle,
                                      'u_view'.encode('utf-8'))
        gl.glUniformMatrix4fv(loc, 1, False, self.view)
        loc = gl.glGetUniformLocation(self._prog_handle,
                                      'u_model'.encode('utf-8'))
        gl.glUniformMatrix4fv(loc, 1, False, self.model)
        loc = gl.glGetUniformLocation(self._prog_handle,
                                      'u_projection'.encode('utf-8'))
        gl.glUniformMatrix4fv(loc, 1, False, self.projection)

        # Draw
        if use_buffers:
            gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, self._faces_handle)
            gl.glDrawElements(gl.GL_TRIANGLES, faces.size, gl.GL_UNSIGNED_INT,
                              None)
        else:
            gl.glDrawElements(gl.GL_TRIANGLES, faces.size, gl.GL_UNSIGNED_INT,
                              faces)
示例#25
0
    def on_paint(self, event):

        # Clear
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        # Draw
        with self._program as prog:
            # You can set uniforms/attributes here too
            prog['sizeFactor'] = 0.5 + np.sin(time.time() * 3) * 0.2

            # Draw (pick one!)
            #prog.draw_arrays(gl.GL_TRIANGLE_STRIP)
            prog.draw_elements(gl.GL_TRIANGLES, indices_buffer)
            #prog.draw_elements(gl.GL_TRIANGLES, indices)  # Not recommended

        self.update()
示例#26
0
文件: fireworks.py 项目: joe311/vispy
    def on_paint(self, event):

        # Clear
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

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

        # Invoke a new draw
        self.update()

        # New explosion?
        if time.time() - self._starttime > 1.5:
            self._new_explosion()
示例#27
0
 def on_paint(self, event):
     
     # Clear
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     
     # Draw
     with self._program as prog:
         # You can set uniforms/attributes here too
         prog['sizeFactor'] = 0.5 + np.sin(time.time()*3)*0.2
        
         # Draw (pick one!)
         #prog.draw_arrays(gl.GL_TRIANGLE_STRIP)
         prog.draw_elements(gl.GL_TRIANGLES, indices_buffer)
         #prog.draw_elements(gl.GL_TRIANGLES, indices)  # Not recommended
     
     self.update()
示例#28
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()
示例#29
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()
示例#30
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()
示例#31
0
    def on_paint(self, event):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        # Filled cube
        with self.program as prog:
            gl.glDisable(gl.GL_BLEND)
            gl.glEnable(gl.GL_DEPTH_TEST)
            gl.glEnable(gl.GL_POLYGON_OFFSET_FILL)
            prog['u_color'] = 1, 1, 1, 1
            prog.draw_elements(gl.GL_TRIANGLES, self.filled)

        # Outline
        with self.program as prog:
            gl.glDisable(gl.GL_POLYGON_OFFSET_FILL)
            gl.glEnable(gl.GL_BLEND)
            gl.glDepthMask(gl.GL_FALSE)
            prog['u_color'] = 0, 0, 0, 1
            prog.draw_elements(gl.GL_LINES, self.outline)
            gl.glDepthMask(gl.GL_TRUE)
示例#32
0
    def on_paint(self, event):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        
        with self.program as prog:
            # Filled cube
            gl.glDisable( gl.GL_BLEND )
            gl.glEnable( gl.GL_DEPTH_TEST )
            gl.glEnable( gl.GL_POLYGON_OFFSET_FILL )
            prog['u_color'] = 1,1,1,1
            prog.draw(gl.GL_TRIANGLES, self.filled_buf)

            # Outline
            gl.glDisable( gl.GL_POLYGON_OFFSET_FILL )
            gl.glEnable( gl.GL_BLEND )
            gl.glDepthMask( gl.GL_FALSE )
            prog['u_color'] = 0,0,0,1
            prog.draw(gl.GL_LINES, self.outline_buf)
            gl.glDepthMask( gl.GL_TRUE )        
示例#33
0
 def on_paint(self, event):
     
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     
     # Activate program  and texture
     gl.glUseProgram(self._prog_handle)
     gl.glBindTexture(gl.GL_TEXTURE_2D, self._tex_handle)
     
     # Set attributes (again, the loc can be cached)
     loc = gl.glGetAttribLocation(self._prog_handle, 'a_position'.encode('utf-8'))
     gl.glEnableVertexAttribArray(loc)
     if use_buffers:
         gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._positions_handle)
         gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, 0, None)
     else:
         gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0)  # 0 means do not use buffer
         gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, 0, positions)
     #
     loc = gl.glGetAttribLocation(self._prog_handle, 'a_texcoord'.encode('utf-8'))
     gl.glEnableVertexAttribArray(loc)
     if use_buffers:
         gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._texcoords_handle)
         gl.glVertexAttribPointer(loc, 2, gl.GL_FLOAT, False, 0, None)
     else:
         gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0)  # 0 means do not use buffer
         gl.glVertexAttribPointer(loc, 2, gl.GL_FLOAT, False, 0, texcoords)
     
     # Set uniforms (note that you could cache the locations)
     loc = gl.glGetUniformLocation(self._prog_handle, 'u_view'.encode('utf-8'))
     gl.glUniformMatrix4fv(loc, 1, False, self.view)
     loc = gl.glGetUniformLocation(self._prog_handle, 'u_model'.encode('utf-8'))
     gl.glUniformMatrix4fv(loc, 1, False, self.model)
     loc = gl.glGetUniformLocation(self._prog_handle, 'u_projection'.encode('utf-8'))
     gl.glUniformMatrix4fv(loc, 1, False, self.projection)
     
     # Draw
     if use_buffers:
         gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, self._faces_handle)
         gl.glDrawElements(gl.GL_TRIANGLES, faces.size, gl.GL_UNSIGNED_INT, None)
     else:
         gl.glDrawElements(gl.GL_TRIANGLES, faces.size, gl.GL_UNSIGNED_INT, faces)
示例#34
0
文件: hello-fbo.py 项目: joe311/vispy
 def on_paint(self, event):
     
     # Set geometry (is no-op if the size does not change)
     self._fbo.set_size(*self.size)
     
     # Draw the same scene as as in hello_quad.py, but draw it to the FBO
     with self._program1 as prog:
         prog.activate_object(self._fbo)
         # Init
         gl.glClearColor(0,0.0,0.5,1);
         gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
         # Draw
         prog.draw_arrays(gl.GL_TRIANGLE_STRIP)
     
     # Now draw result to a full-screen quad
     with self._program2 as prog:
         # Init
         gl.glClearColor(1,1,1,1);
         gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
         # Draw
         prog.draw_arrays(gl.GL_TRIANGLE_STRIP)
示例#35
0
文件: hello-fbo.py 项目: joe311/vispy
    def on_paint(self, event):

        # Set geometry (is no-op if the size does not change)
        self._fbo.set_size(*self.size)

        # Draw the same scene as as in hello_quad.py, but draw it to the FBO
        with self._program1 as prog:
            prog.activate_object(self._fbo)
            # Init
            gl.glClearColor(0, 0.0, 0.5, 1)
            gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
            # Draw
            prog.draw_arrays(gl.GL_TRIANGLE_STRIP)

        # Now draw result to a full-screen quad
        with self._program2 as prog:
            # Init
            gl.glClearColor(1, 1, 1, 1)
            gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
            # Draw
            prog.draw_arrays(gl.GL_TRIANGLE_STRIP)
示例#36
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])
示例#37
0
def on_paint(event):
    gl.glClearColor(0.2, 0.4, 0.6, 1.0)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
示例#38
0
 def on_paint(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     with self._program as prog:
         prog.draw_arrays(gl.GL_TRIANGLE_STRIP)
示例#39
0
文件: buffer.py 项目: joe311/vispy
 def display():
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     glut.glutSwapBuffers()
示例#40
0
 def on_paint(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     self.program.draw(gl.GL_LINE_STRIP)
示例#41
0
    def on_paint(self, event):

        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        # Swap buffers
        self.swap_buffers()
示例#42
0
 def display():
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     glut.glutSwapBuffers()
示例#43
0
文件: start.py 项目: joe311/vispy
def on_paint(event):
    gl.glClearColor(0.2, 0.4, 0.6, 1.0)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
示例#44
0
 def on_paint(self, event):
     
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     
     self.program.draw(gl.GL_TRIANGLES, faces_buffer)
示例#45
0
 def on_paint(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     with self.program as prog:
         prog.draw_arrays(gl.GL_LINE_STRIP)
示例#46
0
 def on_paint(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
示例#47
0
文件: simple.py 项目: joe311/vispy
 def on_paint(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
示例#48
0
 def on_paint(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     with self.program as prog:
         prog.draw_arrays(gl.GL_POINTS)
示例#49
0
 def on_paint(self, event):
     print('on_paint')
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
示例#50
0
 def on_paint(self, event):
     # Clear
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     # Draw
     with self.program as prog:
         prog.draw_arrays(gl.GL_POINTS)
示例#51
0
文件: app-glut.py 项目: joe311/vispy
 def on_paint(self, event):
     print('on_paint')
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)