我试图使用VBO优化我的opengl应用程序,现在它使用顶点数组完美地工作但是当我使用VBO时不渲染任何东西都不会抛出任何异常。我见过的所有教程都使用了类似的方法。 以下是上传和呈现这些VBO的代码。
def uploadToVRAM(self):
usage = GL_STATIC_DRAW
if self.vertices_VBO == None:
self.vertices_VBO = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, self.vertices_VBO)
glBufferData(GL_ARRAY_BUFFER, ADT.arrayByteCount(self.vertices), ADT.voidDataPointer(self.vertices), usage)
#glBufferData(GL_ARRAY_BUFFER, self.vertices, usage)
#print "Bytes:",ADT.arrayByteCount(self.vertices)
if self.normals != None:
if self.normals_VBO == None:
self.normals_VBO = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, self.normals_VBO)
glBufferData(GL_ARRAY_BUFFER, ADT.arrayByteCount(self.normals), ADT.voidDataPointer(self.normals), usage)
#glBufferData(GL_ARRAY_BUFFER, self.normals, usage)
if self.colors != None:
if self.colors_VBO == None:
self.colors_VBO = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, self.colors_VBO)
glBufferData(GL_ARRAY_BUFFER, ADT.arrayByteCount(self.colors), ADT.voidDataPointer(self.colors), usage)
#glBufferData(GL_ARRAY_BUFFER, self.colors, usage)
if self.uvs != None:
if self.uvs_VBO == None:
self.uvs_VBO = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, self.uvs_VBO)
glBufferData(GL_ARRAY_BUFFER, ADT.arrayByteCount(self.uvs), ADT.voidDataPointer(self.uvs), usage)
#glBufferData(GL_ARRAY_BUFFER, self.uvs, usage)
glBindBuffer(GL_ARRAY_BUFFER,0)
这是渲染部分:
def renderVBOs(self, primitive):
#active arrays
glEnableClientState(GL_VERTEX_ARRAY)
glBindBuffer(GL_ARRAY_BUFFER, self.vertices_VBO)
glVertexPointer(3, GL_FLOAT, 0, 0) #offset in bytes
if self.normals != None:
glEnableClientState(GL_NORMAL_ARRAY)
glBindBuffer(GL_ARRAY_BUFFER_ARB, self.normals_VBO)
glNormalPointer(GL_FLOAT,0, 0)
if self.colors != None:
glEnableClientState(GL_COLOR_ARRAY)
glBindBuffer(GL_ARRAY_BUFFER_ARB, self.colors_VBO)
glColorPointer(4,GL_FLOAT,0, 0 )
if self.uvs != None:
glEnableClientState(GL_TEXTURE_COORD_ARRAY)
glBindBuffer(GL_ARRAY_BUFFER_ARB, self.uvs_VBO)
glTexCoordPointer(2,GL_FLOAT,0, 0 )
glBindBuffer(GL_ARRAY_BUFFER_ARB,0)
#render
glDrawArrays(primitive, 0, self.num_vertex)
#clear
glDisableClientState(GL_VERTEX_ARRAY)
if self.normals != None:
glDisableClientState(GL_NORMAL_ARRAY)
if self.colors != None:
glDisableClientState(GL_COLOR_ARRAY)
if self.uvs != None:
glDisableClientState(GL_TEXTURE_COORD_ARRAY)
glBindBuffer(GL_ARRAY_BUFFER_ARB,0)
答案 0 :(得分:0)
通过查看代码,我注意到一个可能的问题和一个可能的问题:
glDrawArrays
如果这无助于尝试制作一个最小的可运行示例,我们可以使用它来使其工作。