Archive for pyopengl

Using ARRAY_BUFFER’s in PyOpenGL

Posted in How To, Programming, PyGLy with tags , , , , on 2013/02/16 by Adam Griffiths

I’m in the process of converting my code from Pyglet GL to PyOpenGL.
In doing so, my VBO objects stopped rendering.

It turns out the problem is glVertexAttribPointer.
The Pyglet GL version takes the last parameter (offset) as a number. I set this to 0 for arrays with no offset.

glVertexAttribPointer( in_position, 3, GL_FLOAT, GL_FALSE, 0, 0)

It seems that PyOpenGL expects the pointer value by absolute instead of relative.
The solution is to pass None instead of 0.

glVertexAttribPointer( in_position, 3, GL_FLOAT, GL_FALSE, 0, None)

If you have an actual offset to pass, you need to convert to a ctypes c_void_p (void*).
http://stackoverflow.com/questions/11132716/how-to-specify-buffer-offset-with-pyopengl

glVertexAttribPointer( in_position, 3, GL_FLOAT, GL_FALSE, 0, ctypes.c_void_p(offset))

Advertisements
%d bloggers like this: