Building Grids in OpenGL

I am doing OpenGL tests (2.1), and trying to make a simple cube, I was wondering how to create complex meshes. For my cube, I just manually set each vertex using GL_TRIANGLES . But I do not know how to do the same inside a loop, for example. Because of the order of the vertices and because there are so many repeated vertices!

Do I really need to make a face by setting 3 vertices "once" (for both triangles)? It seems so slow. How to optimize?

enter image description here

What are the methods for creating / loading grids?

Oh, I would appreciate some example.

+4
source share
1 answer

Jason Gregory’s Gaming Machine Architecture has the answer to your question. Here is what he says:

The easiest way to define a grid is to copy the vectices into groups of three [...] This data structure is known as the Triangular list. [...] You probably noticed that many vertices were duplicated, often several times [...] For this reason, most engines use a more efficient data structure, known as an indexed list of triangles

The idea of ​​indexed triangle lists is to store vertices in a separate vertex buffer and indexes in a separate index buffer.

In the same chapter, it is also recommended to use triangular stripes ( GL_TRIANGLE_STRIP ) and fans ( GL_TRIANGLE_FAN )

A tutorial on indexing vertex buffer objects can be found here.

+5
source

Source: https://habr.com/ru/post/1445167/


All Articles