def __init__(self, id, points): self.id = id self.datastring = array.array('f', points).tostring() glEnableClientState(GL_VERTEX_ARRAY) glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.id) glBufferDataARB(GL_ARRAY_BUFFER_ARB, len(self.datastring), self.datastring, GL_STATIC_DRAW_ARB)
def _loaddata(self): a = array.array(self.elementType, self.indices) self.datastring = a.tostring() glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, self.id) glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, len(self.datastring), self.datastring, self.usage) glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0)
def onDraw( self ): glDisable(GL_TEXTURE_2D) glDisable(GL_LIGHTING) glEnableClientState( GL_VERTEX_ARRAY ) glBindBufferARB( GL_ARRAY_BUFFER_ARB, 1 ) graphext.VertexOffset( 3, GL_FLOAT, 0 ) glDrawArrays(GL_TRIANGLES, 0, 3) glEnable(GL_TEXTURE_2D )
def onDraw(self): glDisable(GL_TEXTURE_2D) glDisable(GL_LIGHTING) glEnableClientState(GL_VERTEX_ARRAY) glBindBufferARB(GL_ARRAY_BUFFER_ARB, 1) graphext.VertexOffset(3, GL_FLOAT, 0) glDrawArrays(GL_TRIANGLES, 0, 3) glEnable(GL_TEXTURE_2D)
def draw(self, mode=GL_TRIANGLES, count=None, offset=0): #glDrawElements( GL_TRIANGLES, 1, self.glTypeCode, 0 ) if count == None: count = len(self.indices) glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, self.id) graphext.DrawElementsVB(mode, count, self.glTypeCode, 0) GraphicsCard.recordDraw(int(count / 3)) glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0)
def _upload(self): """Copies all the vertex data to the graphics card""" #determine the offsets for each block and the total size offset = 0 for block in self.dataBlocks: block.offset = offset offset += block.sizeInBytes self.totalSize = offset #create one monolithic data string and give it to opengl self.datastring = ''.join([x.datastring for x in self.dataBlocks]) glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.id) glBufferDataARB(GL_ARRAY_BUFFER_ARB, len(self.datastring), self.datastring, self.usage) glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0)
def bind(self): glBindBufferARB( GL_ARRAY_BUFFER_ARB, self.id ) graphext.VertexOffset( 3, GL_FLOAT, 0 )
def __init__(self, id, points): self.id = id self.datastring = array.array( 'f', points).tostring() glEnableClientState( GL_VERTEX_ARRAY ) glBindBufferARB( GL_ARRAY_BUFFER_ARB, self.id ) glBufferDataARB( GL_ARRAY_BUFFER_ARB, len( self.datastring ), self.datastring, GL_STATIC_DRAW_ARB );
def bind(self): glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.id) graphext.VertexOffset(3, GL_FLOAT, 0)
def unbind(self): glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0)
def bind(self): glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, self.id)
def unbind(self): """Unbinds the buffer for OpenGL""" glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0)
def bind(self): """Binds the buffer for OpenGL""" glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.id) for block in self.dataBlocks: block.bind()