0

I am using OpenGL with the Python bindings. I am passing my faces to OpenGL with the following code:

glBegin(GL_TRIANGLES)
for i in range(len(triangles)):
    glVertex3fv(triangles[i])
glEnd()

where triangles is a list of faces.

This part of the code seems to be rather slow, taking on the order of a few seconds for a mesh of ~10,000 faces. Is there a simple way to speed it up, perhaps passing across all the triangles at once instead of using this for loop?

Bill Cheatham
  • 11,396
  • 17
  • 69
  • 104
  • You can use display list to improve performance. You need to do almost no change in your code to use it. See http://pyopengl.sourceforge.net/documentation/manual-3.0/glNewList.html – Amadeus May 08 '14 at 18:21
  • @TomásBadan: Display Lists are deprecated and have been removed from modern OpenGL. – datenwolf May 08 '14 at 18:22
  • 1
    @datenwolf I agree, but he is using the pair glBegin/glEnd. To improve performance without changing the code (at least at minimum possible), display list is a good option. By the way, that is why I wrote in comment, because this is not the answer. – Amadeus May 08 '14 at 18:25
  • On top of that, you can consider using a primitive type that shares vertices (e.g. strip or fan). Triangle lists (`GL_TRIANGLES`) will duplicate the same vertices dozens of times over, but if your mesh is all connected it probably has a natural strip or fan ordering and most modeling software can spit out data in that more efficient order. – Andon M. Coleman May 09 '14 at 21:26

1 Answers1

2

You're looking for vertex arrays. Ideally you combine it with Vertex Buffer Objects to put the geometry data in fast memory.

Here's a tutorial

http://ltslashgt.com/2007/08/31/vertex-buffer-object-pyopengl/

datenwolf
  • 159,371
  • 13
  • 185
  • 298