index array?

Hi,

thank you for your answer. I have some difficulties to understand “the index array” in the third part of your answer. Could you be more accurate?

thank you

Okay, what you basicly have is an array of points, right? To tell OpenGL how to draw this points you will need an index.

Looks a bit like that:
Vertex Array
1 -> 0, 0, 1
2 -> 0, 0, -1
3 -> 0, 1, 1
4 -> 0, 1, -1

Face 1 consists of:
1, 2, 3
Face 2 consists of:
2, 3, 4

Index Array looks like:
1, 2, 3, 2, 3, 4

If I don’t messed up stuff this is the right answer to your question.
You might take a look at VRML, they do it exactly like that. For tutorials search google for “vrml tutorial” and take a look at http://www.openvrml.org, from there you can download the help file, it has a pretty good explanation for this stuff.
If I’m wrong with my explanation, please correct me. I wasn’t working with this stuff for a while.

Greets,
Martin

Originally posted by mphanke:
[b]Okay, what you basicly have is an array of points, right? To tell OpenGL how to draw this points you will need an index.

Looks a bit like that:
Vertex Array
1 -> 0, 0, 1
2 -> 0, 0, -1
3 -> 0, 1, 1
4 -> 0, 1, -1

Face 1 consists of:
1, 2, 3
Face 2 consists of:
2, 3, 4

Index Array looks like:
1, 2, 3, 2, 3, 4

If I don’t messed up stuff this is the right answer to your question.
You might take a look at VRML, they do it exactly like that. For tutorials search google for “vrml tutorial” and take a look at http://www.openvrml.org, from there you can download the help file, it has a pretty good explanation for this stuff.
If I’m wrong with my explanation, please correct me. I wasn’t working with this stuff for a while.

Greets,
Martin

[/b]

yes this is that I wanted to know. I understand that you explain. But I would like explain to you more accuratly my problem:
I compute 100 points with B-spline function(u and v parameters). So I have to store them somewhere. I decided to store them in a linear array called curves in this way.
for v
for u
curves[index]=p(u,v);
index++;

But I can hear and read that it is better to use an index array. And I can’t see how to store the vertex somewhere else than in a linear array. Then I can use an index array.
In other way, if I use your example, where do you store the coordinates of each point:
0,0,1
0,0,1
0, 1, 1
0, 1, -1

I’m not sure that my explanation was very clear

thanks you anyway !!!

Hi, sorry I didn’t get back to you sooner. Ok, you still want to have your vertex array. The vertex array is just essentially a long string of numbers, where every 3 consecutive values represent a vertex, like this ->( 2.0 3.0f 2.0f , 1.0 3.3 2.1 ) Here there are two vertices, seperated by the comma for clarity. In reality this would be much longer.

Now an index array is just an array of ints, like this -> ( 1, 2, 3, 2, 3, 4, 3, 4, 5 ) where a value of 1 would reference vertex 1, and a value of 2 would reference vertex 2, and so on. Using an index array allows you to store just the unique vertices, then render the vertices in the order of the index array. If you are storing a lot of vertices, then using an index array can result in mass memory savings.

Once you have built your arrays, you tell OpenGL that you want to use it.

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,0,vertexarray);

// then to draw the vertices using your index array…
glDrawElements(primitive type here,count,GL_UNSIGNED_INT,indexarray);

Hope this makes things clearer for you.

Old GLman

Ok,

I think i understood the idea. So I can keep my linear array to store all the vertices computed and use an index array to reference the linear array. If I do :

linear array:
0 -> 0.34 0.32 1.57
1 -> 0.34 0.32 1.55
2 -> 0.54 0.2 1.5
3 -> 0.3 0.52 1.66
4 -> 0.34 0.72 0.6
5 -> 0.4 0.2 1.6

index array:

0 -> 0 1 2
1 -> 1 2 3
2 -> 3 4 5
3 -> 0 4 3

etc…

to display :
for (i=0;i<3;i++)
glVertex3fv(linearArray[indexArray[i]]

Correct?

Hi, yes that method will work.

Old GLman

great. thank you very much

If you are speaking of glIndexPointer, I’m pretty sure that refers to color indices and not vertex indices.

If you want to use a vertex array and refer to the vertices by index, that’s just a vertex array; index arrays have nothing to do with that, so you don’t get confused. I know I did at first.