vbo,ibo + Normals


drawing a Cube with vbo is not difficult. I define 8 vertices and
then create some indices to draw triangles with that given 8 vertices. But how to handle the normals ? When I wanted to have normales for each triangles, I created as much vertices I need for triangles.

For example, draw a cube with triangles need normally 36 triangles. 6 Faces and 2 triangles per face. When I create a cube with redundant vertices (36) and define a normal for each vertex, it’s easy to understand how to use the normals. But how
to handle it, with just 8 vertices and an amount of 12 normnals, or 6 normals.


It isn’t possible; each vertex can only be associated with a single normal. In this case, you would have to use 24 separate vertexes.

tanks for the fast answer.

for a cube, all normals are directly orthogonal to the plane of the triangle.
so I believe that you could use a geometry shader which would compute the normal with a cross product for each triangle. in that case, you don’t need to even allocate any normal array, or to duplicate any vertex.

another approach is to bind two additional texture buffers in your vertex shader:

  • the first one will be indexed by gl_VertexID and will return the index of the normal (size == 36)
  • the second one will return the float value of the normals, and will be indexed by the value of the first texbo (size==6)

Thanks Pierre,
I think you are talking about instancing, right? Also considered about this.


this was not instancing, but you could use it to solve your problem as well.