Search code examples
pythonopenglpyopengl

PyOpenGL. glVertexPointer loads RAM to infinity


All works, but RAM loads very fast, i think its glVertexPointer in cycle. Here is my simplified code

...
pygame.init()
display = (800, 600)
screen = pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
glClearColor(4/255, 4/255, 22/255, 1)
glEnableClientState(GL_VERTEX_ARRAY)
VBO = glGenBuffers(1)
...

while True:
    ....

    vertices = vertices @ A           # A = np.array((3, 3)), vertices = np.array((N, 3)), N~2000
    vertices1 = np.ravel(vertices)
    glBindBuffer(GL_ARRAY_BUFFER, VBO)
    glVertexPointer(3, GL_FLOAT, 0, vertices1)
    # glBufferSubData(GL_ARRAY_BUFFER, 0, vertices1.nbytes, vertices1)
    glDrawArrays(GL_LINES, 0, l_v)
...

if comment this, RAM not loads:

# glVertexPointer(3, GL_FLOAT, 0, vertices1)

i'm new one in OpenGL, and don't know right ways to do what i want. I want to manipulate with vertices dynamically in time. And it so happened that my computer is old, and installed OpenGL 2.0. Help me please


Solution

  • this is solved my problem with RAM

    import array
    vertices1 = array.array('f', vertices1)
    glVertexPointer(3, GL_FLOAT, 0, vertices1.tobytes() )
    

    but converting lowered fps from 100 to 30, i use two converting for a cycle

    upd.

    this works ideal

    vertices1 = np.ravel(vertices)
    vertices1 = np.array(vertices1, dtype='f')
    glVertexPointer(3, GL_FLOAT, 0, vertices1.tobytes() )