Search code examples
pythonopenglpyopengl

Print the content of a VBO


I'm modifying bits of a OpenGL_accelerate.vbo.VBO object at different moments, and I'd like to print the actual whole content this object (for debug purpose).

A simple print(my_vbo) doesn't work (it prints <OpenGL_accelerate.vbo.VBO object at 0x0000019FA8370430>)

Is there a simple way to get it with PyOpenGL (or must I maintain a numpy copy of the data) ?


Solution

  • You need to create an array of GLfloat and read the buffer back from the GPU into that array with glGetBufferSubData. Finally, you can print the array as a list

    glBindBuffer(GL_ARRAY_BUFFER, vbo)
    
    no_of_floats = 12 # read 12 floats
    float_array = (GLfloat * no_of_floats)()
    glGetBufferSubData(GL_ARRAY_BUFFER, 0, no_of_floats * sizeof(GLfloat), float_array)
    print(list(float_array))