PDA

View Full Version : index array?

zip7000
05-03-2002, 08:19 AM
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

mphanke
05-03-2002, 01:53 PM
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

zip7000
05-03-2002, 03:52 PM
Originally posted by mphanke:
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

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 http://www.opengl.org/discussion_boards/ubb/smile.gif

thanks you anyway !!!

Old GLman
05-03-2002, 04:47 PM
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

zip7000
05-03-2002, 05:03 PM
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?

Old GLman
05-03-2002, 05:33 PM
Hi, yes that method will work.

Old GLman

zip7000
05-04-2002, 03:25 AM
great. thank you very much

Omaha
05-05-2002, 04:49 PM
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.