Bartvbl
Bartvbl

Reputation: 2928

How should the data of an index array of a VBO be formatted?

I am trying to implement a VBO in my application. Now I have understood how they work, and how to use them, yet I don't have a single clue on how to fill the accompanying index buffer. Strangely enough I haven't found any tutorial explaining this at all.

Say that I have 3 buffers like this:

vertex buffer: (3, 4, 7), (2, 4, 7), (2, 4, 2), ...

texture buffer: (1, 1), (0, 1), (1, 0), (1, 1), ..

normal buffer: (4, 2, 6), (3, 2, 7), (2, 4, 5) ...

How do I tell openGL that I want it to draw a vertex at (3, 4, 7) with a texture coordinate of (1, 1) and a normal of (4, 2, 6) and so on? And how do I put this data in the right format in the elements index buffer?

Upvotes: 2

Views: 669

Answers (1)

genpfault
genpfault

Reputation: 52083

The index buffer just contains integer offsets into your VBO arrays. For your example your first index buffer element should be 0, since you want to draw the zeroth element of your vertex, texture, and normal arrays.

Note that it's the same offset into all three arrays.

Upvotes: 2

Related Questions