示例#1
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()
示例#2
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()
示例#3
0
 def draw00(event):
     print('  {0:7}: {1}'.format('0', bgcolors[0]))
     if bgcolors[0] is not None:
         gl.glViewport(0, 0, *list(_win_size))
         gl.glClearColor(*bgcolors[0])
         gl.glClear(gl.GL_COLOR_BUFFER_BIT)
         gl.glFinish()
示例#4
0
 def paint0(event):
     print('  {0:7}: {1}'.format(backend + '_0', bgcolors[0]))
     if bgcolors[0] is not None:
         gl.glViewport(0, 0, *list(_win_size))
         gl.glClearColor(*bgcolors[0])
         gl.glClear(gl.GL_COLOR_BUFFER_BIT)
         gl.glFinish()
    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)
示例#6
0
 def draw11(event):
     print('  {0:7}: {1}'.format('1', bgcolors[1]))
     if bgcolors[1] is not None:
         gl.glViewport(0, 0, *list(_win_size))
         gl.glClearColor(*bgcolors[1])
         gl.glClear(gl.GL_COLOR_BUFFER_BIT)
         gl.glFinish()
示例#7
0
 def draw00(event):
     print("  {0:7}: {1}".format("0", bgcolors[0]))
     if bgcolors[0] is not None:
         gl.glViewport(0, 0, *list(_win_size))
         gl.glClearColor(*bgcolors[0])
         gl.glClear(gl.GL_COLOR_BUFFER_BIT)
         gl.glFinish()
示例#8
0
文件: texturing.py 项目: ds604/vispy
 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)
示例#9
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)
示例#10
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()
示例#11
0
 def on_draw(self, event):
     t = timeit.default_timer()
     self.times.append(t)
     if len(self.times) >= 2:
         print(1./(t-self.times[-2]))
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     gl.glDrawArrays(gl.GL_POINTS, 0, len(self.data))
     self.update()
示例#12
0
 def on_paint(self, event):
     # Clear
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     # Correct way to draw the terrain
     #self.program.draw(gl.GL_TRIANGLES)
     """Drawing as line strip is wrong as the VB represents triangles but
     it gives better visualization of the terrain with minor mistakes
     """
     self.program.draw(gl.GL_TRIANGLES)
示例#13
0
 def on_paint(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     # update angles
     data['a_omega'] += do
     data['a_theta'] += dt
     # prevent accumulation
     data['a_omega'] %= 2 * np.pi
     data['a_theta'] %= 2 * np.pi
     self.vbo.set_data(data)
     self.program.draw(gl.GL_POINTS)
示例#14
0
    def on_draw(self, event):

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

        if self.render_params['draw_polygons']:
            self.draw_model()

        if self.render_params['draw_points']:
            self.draw_points()
示例#15
0
    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()
示例#16
0
文件: boids.py 项目: LiloD/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()
示例#17
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()
示例#18
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()
示例#19
0
文件: atom.py 项目: ds604/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.vbo.set_data(data)
        self.program.draw(gl.GL_POINTS)
示例#20
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()
示例#21
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
        self.vbo.set_data(data)
        self.program.draw(gl.GL_POINTS)
    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()
示例#23
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()
示例#24
0
def _test_setting_stuff():
    # Set stuff to touch functions

    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    #
    gl.glBlendColor(1.0, 1.0, 1.0, 1.0)
    gl.glBlendEquation(gl.GL_FUNC_ADD)
    gl.glBlendEquationSeparate(gl.GL_FUNC_ADD, gl.GL_FUNC_ADD)
    gl.glBlendFunc(gl.GL_ONE, gl.GL_ZERO)
    gl.glBlendFuncSeparate(gl.GL_ONE, gl.GL_ZERO, gl.GL_ONE, gl.GL_ZERO)
    #
    gl.glClearColor(0.0, 0.0, 0.0, 1.0)
    gl.glClearDepth(1)
    gl.glClearStencil(0)
    #
    gl.glColorMask(True, True, True, True)
    gl.glDepthMask(False)
    gl.glStencilMask(255)
    gl.glStencilMaskSeparate(gl.GL_FRONT, 128)
    #
    gl.glStencilFunc(gl.GL_ALWAYS, 0, 255)
    gl.glStencilFuncSeparate(gl.GL_FRONT, gl.GL_ALWAYS, 0, 255)
    gl.glStencilOp(gl.GL_KEEP, gl.GL_KEEP, gl.GL_KEEP)
    gl.glStencilOpSeparate(gl.GL_FRONT, gl.GL_KEEP, gl.GL_KEEP, gl.GL_KEEP)
    #
    gl.glFrontFace(gl.GL_CW)
    gl.glHint(gl.GL_GENERATE_MIPMAP_HINT, gl.GL_FASTEST)
    gl.glLineWidth(2.0)
    gl.glPolygonOffset(0.0, 0.0)
    gl.glSampleCoverage(1.0, False)

    # And getting stuff
    try:
        with use_log_level('error', print_msg=False):
            r, p = gl.glGetShaderPrecisionFormat(gl.GL_FRAGMENT_SHADER,
                                                 gl.GL_HIGH_FLOAT)
            gl.check_error()  # Sometimes the func is there but OpenGL errs
    except Exception:
        pass  # accept if the function is not there ...
        # We should catch RuntimeError and GL.error.NullFunctionError,
        # but PyOpenGL may not be available.
        # On Travis this function was not there on one machine according
        # to PyOpenGL, but our desktop backend worked fine ...

    #
    v = gl.glGetParameter(gl.GL_VERSION)
    assert_true(isinstance(v, string_types))
    assert_true(len(v) > 0)

    gl.check_error()
示例#25
0
def _test_setting_stuff():
    # Set stuff to touch functions
    
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    #
    gl.glBlendColor(1.0, 1.0, 1.0, 1.0)
    gl.glBlendEquation(gl.GL_FUNC_ADD)
    gl.glBlendEquationSeparate(gl.GL_FUNC_ADD, gl.GL_FUNC_ADD)
    gl.glBlendFunc(gl.GL_ONE, gl.GL_ZERO)
    gl.glBlendFuncSeparate(gl.GL_ONE, gl.GL_ZERO, gl.GL_ONE, gl.GL_ZERO)
    #
    gl.glClearColor(0.0, 0.0, 0.0, 1.0)
    gl.glClearDepth(1)
    gl.glClearStencil(0)
    #
    gl.glColorMask(True, True, True, True)
    gl.glDepthMask(False)
    gl.glStencilMask(255)
    gl.glStencilMaskSeparate(gl.GL_FRONT, 128)
    #
    gl.glStencilFunc(gl.GL_ALWAYS, 0, 255)
    gl.glStencilFuncSeparate(gl.GL_FRONT, gl.GL_ALWAYS, 0, 255)
    gl.glStencilOp(gl.GL_KEEP, gl.GL_KEEP, gl.GL_KEEP)
    gl.glStencilOpSeparate(gl.GL_FRONT, gl.GL_KEEP, gl.GL_KEEP, gl.GL_KEEP)
    #
    gl.glFrontFace(gl.GL_CW)
    gl.glHint(gl.GL_GENERATE_MIPMAP_HINT, gl.GL_FASTEST)
    gl.glLineWidth(2.0)
    gl.glPolygonOffset(0.0, 0.0)
    gl.glSampleCoverage(1.0, False)
    
    # And getting stuff
    try:
        with use_log_level('error', print_msg=False):
            r, p = gl.glGetShaderPrecisionFormat(gl.GL_FRAGMENT_SHADER,
                                                 gl.GL_HIGH_FLOAT)
            gl.check_error()  # Sometimes the func is there but OpenGL errs
    except Exception:
        pass  # accept if the function is not there ...
        # We should catch RuntimeError and GL.error.NullFunctionError,
        # but PyOpenGL may not be available.
        # On Travis this function was not there on one machine according
        # to PyOpenGL, but our desktop backend worked fine ...
        
    #
    v = gl.glGetParameter(gl.GL_VERSION)
    assert_true(isinstance(v, string_types))
    assert_true(len(v) > 0)
    
    gl.check_error()
示例#26
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()
示例#27
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()
示例#28
0
文件: fireworks.py 项目: LiloD/vispy
    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()
示例#29
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)
示例#30
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()
    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()
示例#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_draw(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._fbo:
            # Init
            gl.glClearColor(0, 0.0, 0.5, 1)
            gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
            # Draw
            self._program1.draw(gl.GL_TRIANGLE_STRIP)

        # Now draw result to a full-screen quad
        # Init
        gl.glClearColor(1, 1, 1, 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        # Draw
        self._program2.draw(gl.GL_TRIANGLE_STRIP)
示例#34
0
文件: hello-fbo.py 项目: ds604/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._fbo:
         # Init
         gl.glClearColor(0,0.0,0.5,1);
         gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
         # Draw
         self._program1.draw(gl.GL_TRIANGLE_STRIP)
     
     # Now draw result to a full-screen quad
     # Init
     gl.glClearColor(1,1,1,1);
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     # Draw
     self._program2.draw(gl.GL_TRIANGLE_STRIP)
示例#35
0
 def on_paint(self, event):
     gl.glClearColor(0.2, 0.4, 0.6, 1.0)
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
     self.program.draw(gl.GL_TRIANGLE_STRIP)
示例#36
0
 def on_paint(self, event):
     print('on_paint')
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
示例#37
0
 def on_draw(self, event):
     print('on_draw')
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
示例#38
0
 def on_draw(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
     gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
示例#39
0
def _clear_screen():
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    gl.glFinish()
示例#40
0
 def on_draw(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     gl.glDrawArrays(gl.GL_POINTS, 0, len(self.data))
示例#41
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)
示例#42
0
 def on_paint(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     I[...] = np.random.uniform(0, 1, (W, H)).astype(np.float32)
     self.texture.set_data(I)
     self.program.draw(gl.GL_TRIANGLE_STRIP)
     self.update()
示例#43
0
 def on_draw(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
     self.program.draw(gl.GL_LINE_STRIP)
示例#44
0
文件: cube.py 项目: Peque/vispy
 def on_draw(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     gl.glDrawElements(gl.GL_TRIANGLES, self.icube_data.size,
                       gl.GL_UNSIGNED_INT, None)
示例#45
0
文件: simple.py 项目: ds604/vispy
 def on_paint(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
示例#46
0
 def on_paint(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     self._program.draw(gl.GL_TRIANGLE_STRIP)
    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)
示例#48
0
 def on_paint(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
示例#49
0
 def on_draw(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     gl.glDrawElements(gl.GL_TRIANGLES, self.icube_data.size,
                       gl.GL_UNSIGNED_INT, None)
示例#50
0
文件: start.py 项目: ds604/vispy
def on_paint(event):
    gl.glClearColor(0.2, 0.4, 0.6, 1.0)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
示例#51
0
 def on_paint(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     self.program.draw(gl.GL_POINTS)
示例#52
0
 def on_paint(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     I[...] = np.random.uniform(0, 1, (W, H)).astype(np.float32)
     self.texture.set_data(I)
     self.program.draw(gl.GL_TRIANGLE_STRIP)
     self.update()
示例#53
0
def _clear_screen():
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    gl.glFinish()
示例#54
0
 def on_draw(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
     self.program.draw(gl.GL_LINE_STRIP)
示例#55
0
 def on_draw(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
     self.program.draw('triangle_strip')