This is a very elementary question. At the moment I am drawing lots of faces separately by setting a location uniform separately for each one of them. This is very slow. As I understand it, the correct way to do this is to build a large mesh and draw it all at once.

I am not sure if I understand how to do this, and since it is quite a bit of work, I would prefer to know before I start doing.

The only thing I can think of is to create a large vertex coordinate array that has the information of global world position instead of the vertex coordinates in -1...1 range, and use that as vertex position attribute without changing the location uniform for each face. Then I need to create a corresponding array that takes care of the indices of the points to form proper faces.

In case this is correct so far, are texture coordinates and face normals produced the same way?


1 Answer 1


A mesh is a simply a list of vertices. There are two ways to organize them into a buffer;

1) Stream all of the vertices into an array, one after the other, like so |X|Y|Z|X|Y|Z|X|Y|Z|... etc

Use the appropriate vertex buffer functions in OpenGL (check here, you can ignore the terrain part).

This is the fastest(depending..) way to process the vertices The problem with this method is that there are potentially a lot of duplicated vertices. Think of a cube, it has 8 vertices, each of those vertices is shared between 6 faces, some of the vertices are shared between 2 triangles! This adds up fast and can cause performance and memory issues.

2) Store all of the unique x,y,z groups in an array, use an array of indices to reference the unique vertices, like so

Verts: |XYZ|XYZ|XYZ|XYZ|... etc

Indices: |1|2|3|4|3|1|... etc

For simple models this is a tiny bit slower, but when you get into more complicated meshes this will save you tons of headaches with caching and overhead and will be faster than method 1. Again, reference the link above for how to do this, the only difference will be activating the index buffer.

To answer the last part of your question, yes. Normals and texture coordinates are done the same way, you'll just pack them into the vertex array with the position.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .