Jump to content
  • Advertisement
Sign in to follow this  
Enjoy

OpenGL Index buffer in OpenGL

This topic is 3770 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!