glDrawElements to draw a cube in PyOpenGL

后端 未结 1 1798
野的像风
野的像风 2021-01-22 18:21

I recently started to learn OpenGL through Python thanks to several tutorial (especially the Nicolas P. Rougier one: http://www.labri.fr/perso/nrougier/teaching/opengl/).

<
相关标签:
1条回答
  • 2021-01-22 18:39
    gl.glDrawElements(gl.GL_TRIANGLES, len(index), gl.GL_UNSIGNED_INT, index)
    

    The index argument has two different meanings depending on whether an ELEMENT_ARRAY_BUFFER is bound or not:

    • If no bound: Then it specifies a pointer to client memory where the indices are stored
    • If a ELEMENT_ARRAY_BUFFER is bound, then the index parameter specifies an offset into this buffer. This defines where in the buffer the indices start.

    In your case, a buffer is bound, so you tell OpenGL to start somewhere in the buffer. But what you want is to start at the beginning of the buffer, thus you have to set index to 0.

    gl.glDrawElements(gl.GL_TRIANGLES, len(index), gl.GL_UNSIGNED_INT, ctypes.c_void_p(0))
    
    0 讨论(0)
提交回复
热议问题