Why is Box using so many indices?

I am currently writing a simplified box that is 1,1,1 in dimension by copying the code from Box and AbstractBox, however I am confused by the way the code does things in those classes.

Why are the Box Indices a 3-component element? I thought those were 1-component ints pointing to the vertex position.

Why is the vertex data duplicated so many times? Essentially there is one set of 4 vertex points for each face, even though 8 vertex total would be sufficient for a box.

Why do the indices duplicate the vertices completely? I though the reason to use indices was to actually reduce the amount of data?

Is there any particular reason why the box is ordered back, right, front, left, top, bottom?

The index buffer represents triangles. Each triangle has 3 corners. The ints represent the vertex number for each corner in a triangle times the number of triangles. The index buffer doesn’t duplicate data. It just contains multiple references to vertices because each triangle needs it.

Only 8 vertices would draw smooth corners on the box in GL, so you need separate vertices for each side, so that they don’t share normals. This is why Box has 24 vertices.
That’s probably closer to answer what you asked.

This is why it appears to duplicate data. With 8 vertices, you’d get the same effect as if you created a box in Blender and set the vertices to “smooth”.

Sorry about all the edits, just improving a bodged answer. I misunderstood the question and answered without thinking first. :slight_smile:

Ok that answers question 1: the box is drawn with triangles, therefore each index component describes 1 triangle.

What about the other questions?

Each face (side) of the box needs its own vertices because they need different normals. This is what Rickard said in his edit.

Ok that makes sense. Also it might be difficult to apply textures properly if vertices are reused.

Have a read here. It might help you understand how shapes are created. The only shape geometries understand is triangles, and every shape is created from them.


For example, here is a sphere made from… you guessed it… triangles.

Thank you, but I am aware how shapes are created. I was just wondering about the duplication of vertices, but it all makes sense once you try to apply the textures.

Before I had been using triangle-strip cubes without textures and light, and those you can draw with just 8 vertices. But that simply won’t work once you apply textures and light.