Exemplo n.º 1
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()
Exemplo n.º 2
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()
Exemplo n.º 3
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()
Exemplo n.º 4
0
def _draw1():
    # Draw using arrays
    gl.glDrawArrays(gl.GL_TRIANGLES, 0, N)
    gl.glFinish()
    _check_result()
Exemplo n.º 5
0
 def on_draw(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
     gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
Exemplo n.º 6
0
def _draw1():
    # Draw using arrays
    gl.glDrawArrays(gl.GL_TRIANGLES, 0, N)
    gl.glFinish()
    _check_result()
Exemplo n.º 7
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))
Exemplo n.º 8
0
 def on_draw(self, event):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
     gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)