How can I create and use a Vertex Buffer Object in Pyglet using a Numpy array containing vertex positions?

497 views Asked by At

I have a numpy array with sets of vertices for a number of triangles that I want to render. The vertex positions are constantly updated.

The vertices are stored in a numpy array in the following format:

[x1,y1,x2,y2,x3,y3;
 x4,y4,x5,y5,x6,y6;
....]

Each row contains the vertices for a single triangle.

1

There are 1 answers

0
JakeJ On

If you are updating the vertexes, then you will want to use a vertex buffer object (VBO). Display lists are faster, but once you make them, you can't change the vertices. Remember that when you update the VBO, the graphics card copies the entire VBO back into its memory from the PC's memory. The bus (memory to GPU memory) is the bottleneck then. Therefore, your game will run faster when you aren't constantly updating this.

Found a site with a minimal example, checked wayback machine and it's from 2015: https://sites.google.com/site/swinesmallpygletexamples/vbo-triangle

Tested code with Python 2.7.5 and Pyglet 1.2.3 - works.