PDA

View Full Version : Calculating triangle strip indices from vertex array



plucky
01-30-2001, 11:10 AM
hello,

i don't think my brain is functioning properly, because i can't figure out how to do something that seems relatively straightforward...

i have a float array that is storing a mesh of vertices that makes up a terrain map, the array is set up so that i can render all the vertices as points by doing this after i enable vertex arrays and point them to my float array:

for(int i = 0; i < numVertices; ++i)
glArrayElement(i);

my problem is that i can't figure out (for whatever reason) how to calculate and store the indices to the vertices that would be needed to render this mesh as a series of triangle strips with a single call to glDrawElements();

i know that the number of strips in the mesh is the length of one column of the mesh minus one, and the number of vertices per strip is two times the width of the mesh... but for some reason i can't quite put it all together and get it to work

i hope that was clear enough...

any help is greatly appreciated!!

--brian

[This message has been edited by plucky (edited 01-30-2001).]

zed
01-30-2001, 05:38 PM
u will need to use multiple calls to glDrawElements

small version

0-3-6-9
|/|/|/|
1-4-7-10 etc
|/|/|/|
2-5-8-11

so one strip is 0,1,3,4,6,7,9,10 and another is 1,2,4,5,7,8,10,11

plucky
01-30-2001, 07:21 PM
shouldn't i be able to figure out the indices for all the tri-strips, smush them all into a single array, and pass the entire array to glDrawElements();?

my problem is filling the index array with index values... i can't seem to come up with an algorithmic way of doing it in code...

plucky
01-31-2001, 10:32 PM
just in case anyone is interested... i think i came up with a way to do this that will work (although i havn't implemented it yet, so i can't say for sure)

given a float array of vertices like so::

float vertArray[width * height * 3];

you can store the indices for tri-strips into an array like this::

int numStrips = height - 1;
int vertsPerStrip = width * 2;
int indexArray[numStrips][vertsPerStrip];

you should be able to fill the indexArray like this (i think... correct me if i'm wrong)




for(int stripCnt = 0; stripCnt < numStrips; ++stripCnt)
{
int indexCnt = 0;
for(int widthCnt = 0; widthCnt < width; ++widthCnt)
{
indexArray[stripCnt][indexCnt] = (stripCnt * width) + widthCnt;
++indexArray;
indexArray[stripCnt][indexCnt] = (stripCnt * width) + widthCnt + width;
++indexArray;
}
}

-plucky

[This message has been edited by plucky (edited 01-31-2001).]

[This message has been edited by plucky (edited 01-31-2001).]