0

I am having trouble texturing my cube using an index buffer. I came across an article saying that you need 24 vertexes defined in your cube instead of only 8 vertexes (where 1 vertex is 3 floats).

What is the point of using index buffers then if you have to transfer so much repeat data?

OpenGL ES - texture map all faces of an 8 vertex cube?

Community
  • 1
  • 1
Matthew
  • 3,886
  • 7
  • 47
  • 84

1 Answers1

1

A vertex is not 3 floats; that's why the answer says that. A vertex is all of the data needed for a single vertex of the output primitive. That includes the position (3 floats), but it also includes any texture coordinates, normals, per-vertex colors, or other vertex attributes you are interested in.

The purpose of the index buffer is to not have to repeat as much data. Each face has 4 independent vertices, but each face is also 2 triangles which share 2 vertices. If you didn't use indexed rendering, then you would need to represent each face as either a separate GL_TRIANGLE_STRIP draw call (so drawing a full cube requires 6 separate draw calls), or you would have to provide 6 vertices per face, where 2 vertices are the exact same vertex data copied over again.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982