Beispiel #1
0
    def createVertexAndTextureBuffers(self, vertices, tcoords, opacity = None):
        ''' Allocate hardware buffers for vertices, texture coordinates, and optionally opacity. '''
        if self.flipHorizontal:
            vertices[:,0] = -vertices[:,0]
        if self.flipVertical:
            vertices[:,1] = -vertices[:,1]

        GL.glEnableClientState (GL.GL_VERTEX_ARRAY)

        #vertex buffer in hardware
        self.gl_vb = GL.GLuint()
        GL.glGenBuffers(1 , self.gl_vb)
        GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.gl_vb)
        GL.glBufferData(GL.GL_ARRAY_BUFFER, ADT.arrayByteCount(vertices), ADT.voidDataPointer(vertices), GL.GL_STATIC_DRAW)

        #vertex buffer tdata in hardware
        self.gl_tb = GL.GLuint()
        GL.glGenBuffers(1 , self.gl_tb)
        GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.gl_tb)
        GL.glBufferData(GL.GL_ARRAY_BUFFER, ADT.arrayByteCount(tcoords), ADT.voidDataPointer(tcoords), GL.GL_STATIC_DRAW)

        # opacity buffer in hardware (only for warp files)
        if opacity is not None:
            self.gl_color = GL.GLuint()
            GL.glGenBuffers(1 , self.gl_color)
            GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.gl_color)
            #convert opacity to RGBA, one point for each corner of the quad
            GL.glBufferData(GL.GL_ARRAY_BUFFER, ADT.arrayByteCount(opacity), ADT.voidDataPointer(opacity), GL.GL_STATIC_DRAW)
        else:
            self.gl_color = None

        GL.glBindBuffer(GL.GL_ARRAY_BUFFER, 0)
        GL.glDisableClientState(GL.GL_VERTEX_ARRAY)
Beispiel #2
0
    def __init__(self, v, i):
        self.__T = mat4()
        v_buff = numpy.array(v, dtype=numpy.float32)
        i_buff = numpy.array(i, dtype=numpy.int16)
        self.__v_hdl = glGenBuffers(1)
        self.__i_hdl = glGenBuffers(1)
        self.__i_size = adt.arrayByteCount(i_buff) * 2

        glBindBuffer(GL_ARRAY_BUFFER, self.__v_hdl)
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.__i_hdl)
        glBufferData(GL_ARRAY_BUFFER, adt.arrayByteCount(v_buff), adt.voidDataPointer(v_buff), GL_STATIC_DRAW)
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, adt.arrayByteCount(i_buff), adt.voidDataPointer(i_buff), GL_STATIC_DRAW)
        if glGetError() != GL_NO_ERROR:
            raise RuntimeError('mesh create error!')
        Engine.get().add_object(Engine.get(), self)
Beispiel #3
0
 def __init__(self, data):
     self.data = data
     self.vbo_id = gl.glGenBuffers(1)
     gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.vbo_id)
     rawGlBufferData(gl.GL_ARRAY_BUFFER, ADT.arrayByteCount(data),
                     ADT.voidDataPointer(data), gl.GL_DYNAMIC_DRAW)
     gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0)
Beispiel #4
0
 def __init__(self, vertbuffer, indexbuffer):
     self.buffer = glGenBuffers(1)
     self.indexbuffer = indexbuffer
     glBindBuffer(GL_ARRAY_BUFFER, self.buffer)
     self.numverts = len(vertbuffer)
     vertbuffer = convertbuffer(vertbuffer)
     glBufferData(GL_ARRAY_BUFFER, ADT.arrayByteCount(vertbuffer), ADT.voidDataPointer(vertbuffer), GL_STATIC_DRAW)
 def __init__(self, data, usage):
     self.buffer = GL.GLuint(0)
     glGenBuffers(1)  # self.buffer)
     self.buffer = self.buffer.value
     glBindBuffer(GL_ARRAY_BUFFER_ARB, self.buffer)
     glBufferData(GL_ARRAY_BUFFER_ARB, ADT.arrayByteCount(data),
                  ADT.voidDataPointer(data), usage)
	def __init__(self, data, usage):
		self.buffer = GLuint(0)
		glGenBuffers(1, self.buffer)
		self.buffer = self.buffer.value
		glBindBuffer(GL_ARRAY_BUFFER, self.buffer)
		glBufferData(GL_ARRAY_BUFFER, ADT.arrayByteCount(data),
		ADT.voidDataPointer(data), usage)
Beispiel #7
0
 def __init__(self, v, i):
     self.__T = mat4()
     self.__verts = numpy.array(v, dtype=numpy.float32)
     self.__ndx = numpy.array(i, dtype=numpy.int16)
     self.__id = glGenBuffers(2)
     glBindBuffer(GL_ARRAY_BUFFER, self.__id[0])
     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.__id[1])
     glBufferData(GL_ARRAY_BUFFER,
                  ARR.arrayByteCount(self.__verts),
                  ARR.voidDataPointer(self.__verts),
                  GL_STATIC_DRAW)
     glBufferData(GL_ELEMENT_ARRAY_BUFFER,
                  ARR.arrayByteCount(self.__ndx),
                  ARR.voidDataPointer(self.__ndx),
                  GL_STATIC_DRAW)
     if glGetError() != GL_NO_ERROR:
         raise RuntimeError('mesh vbo error!')
Beispiel #8
0
 def __init__(self, vertices):
     vertexBufferData = numpy.array(vertices, dtype=numpy.float32)
     self.num_vertices = len(vertices)
     self.vbo = glGenBuffers(1)
     glBindBuffer(GL_ARRAY_BUFFER, self.vbo)
     glBufferData(GL_ARRAY_BUFFER, ADT.arrayByteCount(vertexBufferData),
                  ADT.voidDataPointer(vertexBufferData), GL_STATIC_DRAW)
     glBindBuffer(GL_ARRAY_BUFFER, 0)
Beispiel #9
0
    def set_data(self, data, target):
        self.data = data
        self.target = target

        glBindBuffer(self.target, self.vbo)
        glBufferData(self.target,
                     ArrayDatatype.arrayByteCount(self.data),
                     ArrayDatatype.voidDataPointer(self.data),
                     GL_STATIC_DRAW)
        glBindBuffer(self.target, 0)
Beispiel #10
0
    def draw(self):
        """Render the textbox"""
        # Reload the texture coordinate buffer if anything changed
        if self._dirty:
            # Bind and load the buffer
            glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.__texCoordBuffer)
            glBufferDataARB(GL_ARRAY_BUFFER_ARB,
                            ArrayDatatype.arrayByteCount(self._texCoordArray),
                            ArrayDatatype.voidDataPointer(self._texCoordArray),
                            GL_DYNAMIC_DRAW)

            glBindBufferARB(GL_ARRAY_BUFFER, 0)

            self._dirty = False

        # Set up transformations
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        glTranslatef(self._pos[0], self._pos[1], 0)
        glScalef(0.25, 0.25, 1)

        # Set up the foreground color
        glColor4f(*self._color)

        # Set up the texture
        glEnable(GL_TEXTURE_2D)
        self._charset.bind()
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)

        # Enable vertex and texture arrays
        glEnableClientState(GL_VERTEX_ARRAY)
        glEnableClientState(GL_TEXTURE_COORD_ARRAY)

        # Set the vertex buffer for rendering
        glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.__vertexBuffer)
        glVertexPointer(3, GL_FLOAT, 0, None)

        # Set the texture coordinate buffer for rendering
        glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.__texCoordBuffer)
        glTexCoordPointer(2, GL_FLOAT, 0, None)

        # Unbind the active buffer--pointers are already specified
        glBindBufferARB(GL_ARRAY_BUFFER, 0)

        # Render over everything else
        glDisable(GL_DEPTH_TEST)

        # Render
        glDrawArrays(GL_QUADS, 0, self._cols * self._rows * 4)

        # Disable vertex and texture arrays
        glDisableClientState(GL_VERTEX_ARRAY)
        glDisableClientState(GL_TEXTURE_COORD_ARRAY)
Beispiel #11
0
    def __init__(self, data, usage=GL_STATIC_DRAW):
        """
        Initiate the vertex buffer object on the CPU
        """
        self.buffer = GLuint(0)
        glGenBuffers(1, self.buffer)
        self.buffer = self.buffer.value

        glBindBuffer(GL_ARRAY_BUFFER, self.buffer)
        glBufferData(GL_ARRAY_BUFFER, ADT.arrayByteCount(data),
                     ADT.voidDataPointer(data), usage)
Beispiel #12
0
 def initBuffers(self):
     self.num= len(self.result)
     self.vertices = numpy.ndarray((self.num/4, 4), dtype=numpy.float32)
     for i in range(self.num):
         self.vertices[i/4,i%4] = self.result[i] 
     from OpenGL.arrays import ArrayDatatype as ADT
 
     self.bufferVertices = GLuint(0)
     self.bufferVertices = glGenBuffers(1)
     glBindBuffer(GL_ARRAY_BUFFER_ARB, self.bufferVertices)
     glBufferData(GL_ARRAY_BUFFER_ARB, ADT.arrayByteCount(self.vertices), 
         ADT.voidDataPointer(self.vertices), GL_STATIC_DRAW_ARB)
Beispiel #13
0
  def draw(self):
    """Render the textbox"""
    # Reload the texture coordinate buffer if anything changed
    if self._dirty:
      # Bind and load the buffer
      glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.__texCoordBuffer)
      glBufferDataARB(GL_ARRAY_BUFFER_ARB,
        ArrayDatatype.arrayByteCount(self._texCoordArray),
        ArrayDatatype.voidDataPointer(self._texCoordArray), GL_DYNAMIC_DRAW)

      glBindBufferARB(GL_ARRAY_BUFFER, 0)

      self._dirty = False

    # Set up transformations
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()
    glTranslatef(self._pos[0], self._pos[1], 0)
    glScalef(0.25, 0.25, 1)

    # Set up the foreground color
    glColor4f(*self._color)

    # Set up the texture
    glEnable(GL_TEXTURE_2D)
    self._charset.bind()
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)

    # Enable vertex and texture arrays
    glEnableClientState(GL_VERTEX_ARRAY)
    glEnableClientState(GL_TEXTURE_COORD_ARRAY)

    # Set the vertex buffer for rendering
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.__vertexBuffer)
    glVertexPointer(3, GL_FLOAT, 0, None)

    # Set the texture coordinate buffer for rendering
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.__texCoordBuffer)
    glTexCoordPointer(2, GL_FLOAT, 0, None)

    # Unbind the active buffer--pointers are already specified
    glBindBufferARB(GL_ARRAY_BUFFER, 0)

    # Render over everything else
    glDisable(GL_DEPTH_TEST)

    # Render
    glDrawArrays(GL_QUADS, 0, self._cols * self._rows * 4)

    # Disable vertex and texture arrays
    glDisableClientState(GL_VERTEX_ARRAY)
    glDisableClientState(GL_TEXTURE_COORD_ARRAY)
Beispiel #14
0
    def __init__(self, data, usage):
        self.buffer = GLuint(0)
        self.buffer = glGenBuffers(1)
        self.usage = usage
        self.data = data

        # Add a little warning
        if data.dtype == np.float:
            Warning('This float array is 64 bit')

        glBindBuffer(GL_ARRAY_BUFFER, self.buffer)
        glBufferData(GL_ARRAY_BUFFER, ADT.arrayByteCount(data),
                     ADT.voidDataPointer(data), usage)
        glBindBuffer(GL_ARRAY_BUFFER, 0)
Beispiel #15
0
 def __init__(self, data, usage):
   self.buffer = GLuint(0)
   self.buffer = glGenBuffers(1)
   self.usage = usage
   self.data = data
   
   # Add a little warning
   if data.dtype == np.float:
     Warning('This float array is 64 bit')
   
   glBindBuffer(GL_ARRAY_BUFFER, self.buffer)
   glBufferData(GL_ARRAY_BUFFER, ADT.arrayByteCount(data),
                ADT.voidDataPointer(data), usage)
   glBindBuffer(GL_ARRAY_BUFFER, 0)
Beispiel #16
0
    def __init__(self, ui, pos, rows, cols, color=COLOR_WHITE):
        """Initialize the vertex buffer, text array, and texture coordinate
    array"""
        self._pos = pos
        self._rows = rows
        self._cols = cols
        self._color = color
        self._charset = ui.characterSet

        # Set up the vertex buffer
        self.__vertexBuffer = glGenBuffersARB(1)
        glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.__vertexBuffer)

        # Generate the vertices
        vertices = []
        for row in xrange(rows):
            for col in xrange(cols):
                vertices.append((col * self.SCALEX, -row, 0))
                vertices.append(((col + 1) * self.SCALEX, -row, 0))
                vertices.append(((col + 1) * self.SCALEX, -row + 1, 0))
                vertices.append((col * self.SCALEX, -row + 1, 0))

        vertexArray = numpy.array(vertices, dtype=numpy.float32)

        # Load the vertices into the vertex buffer
        glBufferDataARB(GL_ARRAY_BUFFER_ARB,
                        ArrayDatatype.arrayByteCount(vertexArray),
                        ArrayDatatype.voidDataPointer(vertexArray),
                        GL_STATIC_DRAW)

        # Initialize the text array
        self._textArray = numpy.zeros((rows, cols), dtype=numpy.uint8)

        # Set up the texture coordinate buffer
        self.__texCoordBuffer = glGenBuffersARB(1)
        glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.__texCoordBuffer)

        # Initialize all texture coordinates to zero
        self._texCoordArray = numpy.zeros((rows, cols, 4, 2),
                                          dtype=numpy.float32)

        # Force the buffer to be reloaded on the next draw
        self._dirty = True
Beispiel #17
0
  def __init__(self, ui, pos, rows, cols, color=COLOR_WHITE):
    """Initialize the vertex buffer, text array, and texture coordinate
    array"""
    self._pos = pos
    self._rows = rows
    self._cols = cols
    self._color = color
    self._charset = ui.characterSet

    # Set up the vertex buffer
    self.__vertexBuffer = glGenBuffersARB(1)
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.__vertexBuffer)

    # Generate the vertices
    vertices = []
    for row in xrange(rows):
      for col in xrange(cols):
        vertices.append((col * self.SCALEX, -row, 0))
        vertices.append(((col + 1) * self.SCALEX, -row, 0))
        vertices.append(((col + 1) * self.SCALEX, -row + 1, 0))
        vertices.append((col * self.SCALEX, -row + 1, 0))

    vertexArray = numpy.array(vertices, dtype=numpy.float32)

    # Load the vertices into the vertex buffer
    glBufferDataARB(GL_ARRAY_BUFFER_ARB,
      ArrayDatatype.arrayByteCount(vertexArray),
      ArrayDatatype.voidDataPointer(vertexArray), GL_STATIC_DRAW)

    # Initialize the text array
    self._textArray = numpy.zeros((rows, cols), dtype=numpy.uint8)

    # Set up the texture coordinate buffer
    self.__texCoordBuffer = glGenBuffersARB(1)
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.__texCoordBuffer)

    # Initialize all texture coordinates to zero
    self._texCoordArray = numpy.zeros((rows, cols, 4, 2),
      dtype=numpy.float32)

    # Force the buffer to be reloaded on the next draw
    self._dirty = True
Beispiel #18
0
 def makeBuffer(target, data):
     temp = glGenBuffers(1)
     glBindBuffer(target, temp)
     glBufferData(target, ADT.arrayByteCount(data), ADT.voidDataPointer(data), GL_STATIC_DRAW)
     glBindBuffer(target, 0)
     return temp
Beispiel #19
0
 def update_data(self, data, usage):
   glBindBuffer(GL_ARRAY_BUFFER_ARB, self.buffer)
   glBufferData(GL_ARRAY_BUFFER_ARB,
                ADT.arrayByteCount(data),
                ADT.voidDataPointer(data),
                usage)
Beispiel #20
0
 def set_data(self, data):
     self.bind()
     glBufferData(GL_ARRAY_BUFFER, ADT.arrayByteCount(data),
                  ADT.voidDataPointer(data), self.usage)
     self.unbind()
Beispiel #21
0
 def __init__(self, data, usage, type=GL_ARRAY_BUFFER_ARB):
     self.buffer = glGenBuffers(1)
     self.type = type
     glBindBuffer(self.type, self.buffer)
     glBufferData(self.type, ArrayDatatype.arrayByteCount(data), ArrayDatatype.voidDataPointer(data), usage)
     glBindBuffer(self.type, 0)
Beispiel #22
0
 def set_data(self, data):
   self.bind()
   glBufferData(GL_ARRAY_BUFFER, ADT.arrayByteCount(data), ADT.voidDataPointer(data), self.usage)
   self.unbind()
Beispiel #23
0
 def __init__(self, data):
     self.data = data
     self.vbo_id = gl.glGenBuffers(1)
     gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.vbo_id)
     rawGlBufferData(gl.GL_ARRAY_BUFFER, ADT.arrayByteCount(data), ADT.voidDataPointer(data), gl.GL_DYNAMIC_DRAW)
     gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0)
Beispiel #24
0
 def create_index_buffer(self, data, usage=GL_STATIC_DRAW):
     self.index_buffer = glGenBuffers(1)
     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.index_buffer)
     glBufferData(GL_ELEMENT_ARRAY_BUFFER, ADT.arrayByteCount(data),
                  ADT.voidDataPointer(data), usage)
Beispiel #25
0
	def __init__(self, data, usage):
		self.vbo_id = glGenBuffers(2)
		self.buffer = self.vbo_id[0]
		glBindBuffer(GL_ARRAY_BUFFER, self.buffer)
		glBufferData(GL_ARRAY_BUFFER, ADT.arrayByteCount(data), ADT.voidDataPointer(data), usage)