pyopengl
pyopengl copied to clipboard
Suggesting improvement to glVertexAttribPointer(), possibly others
I just spent several hours trying to get my first PyOpenGL code to work. The problem was with the following two lines:
glVertexAttribPointer(vertcoords_loc, 2, GL_FLOAT, False, 16, 0)
glVertexAttribPointer(texcoords_loc , 2, GL_FLOAT, False, 16, 8)
I had to pull and gradually adapt an example found on the internet to finally figure out what I had to change:
glVertexAttribPointer(vertcoords_loc, 2, GL_FLOAT, False, 16, ctypes.c_void_p(0))
glVertexAttribPointer(texcoords_loc , 2, GL_FLOAT, False, 16, ctypes.c_void_p(8))
So, because the OpenGL API defines that the last parameter is a pointer to void even when it actually represents an offset (I'm working with a vertex buffer), PyOpenGL wants me to manually convert that offset into a void pointer using ctypes
.
I'm a total beginner with Python, so I apologies if this is naïve, but wouldn't it be possible here to just drop that constraint, i.e. to implicitly convert the integer to a void pointer?
(Out of curiosity, what kind of implicit conversion is happening when you specify an integer literal as I did? How come no error was detected?)
I concur with this comment. I should be able to pass an integer into the function, without worrying about casting it to a void*, shouldn't I?