4
votes

I'm doing some OpenGL (2.1) tests, and while trying to make a simple cube I was wondering how to make complex meshes. For my cube I just set manualy each vertex with GL_TRIANGLES. But I don't know how to make the same inside a loop for example. Because of the order of the vertices and because there are so many repeated vertices!

I really have to make a face by setting 3 vertex "once" (for both triangles)? That seems so slow. How to optimize?

enter image description here

What are the techniques to make/load meshes?

Oh, I would appreciate some example.

1

1 Answers

5
votes

The book "Game Engine Architecture" by Jason Gregory has the answer to your question. Here is what it says:

The easiest way to define a mesh is to copy vectices in groups of three [...] This data structure is known as Triangle List. [...] You probably noticed that many vertices were duplicated, often multiple times [...] For this reason, most engines make use of a more efficient data structure known as indexed triangle list

The idea behind indexed triangle lists is to store vertices in a separate vertex buffer, and the indices in a separate index buffer.

The same chapter also advises to use triangle strips (GL_TRIANGLE_STRIP) and fans (GL_TRIANGLE_FAN)

A tutorial on vertex buffer object indexing can be found here