glDrawArrays vs glDrawElements

后端 未结 3 831
野趣味
野趣味 2021-01-12 05:57

Ok so I\'m still struggling to get this to work. The important parts of my code are:

def __init__(self, vertices, normals, triangles):
    self.bufferVertice         


        
3条回答
  •  再見小時候
    2021-01-12 06:48

    The reason why

    glDrawElements(GL_TRIANGLES, len(self.triangles) , GL_UNSIGNED_SHORT, ADT.voidDataPointer(self.triangles))
    

    works and

    glDrawElements(GL_TRIANGLES, len(self.triangles) , GL_UNSIGNED_SHORT, 0)
    

    doesn't is because PyOpenGL expects None as the void pointer, rather than 0. Be careful when using OpenGL examples written in C, because they use (void*)0 as the void pointer, which isn't interpreted correctly as a pointer by PyOpenGL, which instead treats 0 as a non-void value.

    Instead, you should use

    glDrawElements(GL_TRIANGLES, len(self.triangles) , GL_UNSIGNED_SHORT, None)
    

    (See also https://stackoverflow.com/a/14365737/478380)

提交回复
热议问题