Sign in to follow this  
nerdtron

vertex and normal arrays by index

Recommended Posts

nerdtron    100
The examples I've seen for using vertex and normal arrays (and also VBOs) provide arrays of vertices and normals directly to GL which it then processes. In my case, I'd like to provide an array of vertices and another array of normals, but then also provide an array of vertex indices and another array of normal indices and have it render using these indices. So rendering a triangle would pull from an array of vertex and normal indices which themselves index into the vertex and normal arrays I've provided. This allows re-using vertex and normal xyz in multiple points. I haven't seen an example with this, though, and thought I'd ask to see if its possible with vertex arrays (and VBOs).

Share this post


Link to post
Share on other sites
aryx    402
I'm having trouble completely understanding your wording, so you may need to clarify. Maybe this will help:

Multiple calls to glDrawElements, or glMultiDrawElements, will allow you to specify multiple sets of indicies with vertex/normal reuse. All you need to do is put all your vertex/normal pairs into an array and then set up multiple index arrays. If you split your vertex/normal data up into separate arrays then the above option won't work.

Share this post


Link to post
Share on other sites
nerdtron    100
I have cases where a single vertex is shared by 2 triangles at a corner, for example, so depending on which triangle that vertex is participating in the normal is different. So to represent it compactly, I'd have the vertex once in a vertex array and 2 entries in the normals array.

Then the first triangle would index the vertex and one of the normals, the next triangle would index the same vertex and the other normal.

As opposed to having to put that vertex in the array twice.

Share this post


Link to post
Share on other sites
nerdtron    100
To clarify what I orginally posted:

I have a vertex array and normal array. Each entry contains xyz data.

Vertex Array: v0 ... vN
Normal Array: n0 ... nN

I then have a triangle array which defines the indices into the vertex array and normal array.

So, each triangle contains a vertex index and normal index for each of the 3 corners.

Drawing the triangles in immediate mode consists of iterating over the triangles, and for each triangle, for each corner, just looking up the vertex and normal from the respective arrays.

This avoids repeating the same xyz data multiple times, it allows a given xyz point to be assigned multiple normals (for the case I mentioned in the previous reply), etc.

Its just that all the examples I've seen with GL have seemed to indicate you have to blow this up and just list all the vertices, and normals, and just repeat them in the array even if they're the same coordinate data.

I was hoping there was an efficient way to supply the triangle vertex and normal indices so that GL would use them to index into the respective arrays.

Share this post


Link to post
Share on other sites
nerdtron    100
thanks for the link! that's a bummer that it can't support that. seems wasteful to duplicate all that data, but at least I can stop searching for a way to do it and just live with the duplication :)

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