Sign in to follow this  
Enjoy

OpenGL Index buffer in OpenGL

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this