Index buffer in OpenGL

Started by
1 comment, last by deathkrush 16 years, 1 month ago
Hello, How is an index buffer in OpenGL organized? I understand, how vertex arrays are passed to OpenGL, but I don't understand how to explain OpenGL, which vertex corresponds to which triangle. For example, I need to pass a square. How could this be done, using index buffers? Thank you in advance, Ilya.
Advertisement
An index buffer is a list of numbers. Each of this numbers is called an index.
If your are drawing triangles the first 3 indices in your IB are for the first triangle,
the indices 4 to 6 are for the second triangle and so on.

So an index buffer which looks like this:
0 1 2 | 1 2 3
would use the 0th, 1st and 2nd vertex from your vertex buffer for the first triangle
and the 1st, 2nd, 3rd vertex for the second triangle.

HtH
The easiest way to understand indexed rendering is to draw a picture of a square and number the vertices:

3---------2|       / ||    /    || /       |0---------1


Put the vertices into the vertex buffer in the same order they are numbered in the picture. Then, just use the index buffer to select those vertices and draw them:

GL_QUADLIST:
0 1 2 3

GL_TRIANGLE_LIST:
0 1 2 0 2 3
deathkrushPS3/Xbox360 Graphics Programmer, Mass Media.Completed Projects: Stuntman Ignition (PS3), Saints Row 2 (PS3), Darksiders(PS3, 360)

This topic is closed to new replies.

Advertisement