# How To Triangle Strip?

Hi,

I have loaded an 8bit grayscale .raw file into an array. The size of the .raw file is 1024x1024, which is the same size as my array. I am using one dimensional array.

I have already implemented my heightmapped terrain using GL_QUADS, but would like to use GL_TRIANGLE_STRIP instead, so my question is:

How do you grab the correct triangle-strip values from my array?

thanks!

1…2…3…4…5…6…7
1.…*
.
2.…*
.
3.…*
.
4.…*
.

For strips, you want the vertices as follows:

(1, 1),
(1, 2),
(2, 1),
(2, 2),
etc.

Notice a pattern here?

glBegin ( GL_TRIANGLE_STRIP)
for ( y = 0; y < ( Height - 1 ); y++ )
{
for ( x = 0; x < Width; x++ )
{
glVertex … (x, y)
glVertex … (x, y+1)
}
}
glEnd ();

[This message has been edited by Robbo (edited 05-17-2002).]

thanks robbo, but i means how do you access your array…i mean, when i load it to my 1024x1024 uint array, how do i access, say, (1,2), or (2,1)…

any more help guys? please? thanks!

i think the equation would be something like

(width * height) + (offset)
width is the width of your image (duh) and height is the row you want to access. Offset is going to be the x component you’re searching for.

so if you had an 8x8 image (64 member array) and you wanted the member that would be at [3][2] if it were a 2d array, you would take

8 x 2 + (3) which would yield 19.
so yourArray[19] is what you’re after
if you sketch out an 8x8 graph and label each box starting at 0, you can see what I mean.

Also, depending on your application, if you know your array will be fixed size, yeilds:

Value = x + ( y << 10 );

Quicker than a multiply - some compilers will optimise for this anyway.

However, I wouldn’t personally advise setting things up for fixed images sizes, unless you always knows its going to be 2^n. In which case, use x + ( y << n ).

ok, i did that, but now my terrain is drawing the whole world in wrong order!.. .

it is like the code is reading the x and y values of my .raw file in backward! but when i used GL_QUADS, it draws just fine…

is the problem in .raw file? is .raw file saved in opposite direction? or is the problem in my array?

Ugh! Lots of possibiles. You can flip your heightfield, or you can generate the vertices in the opposite direction - it all depends on the values you are getting (assuming you are doing some kind of lerp between two points to get the patch vertex x\z positions).

I wrote a sequence of terrain demos. One uses QUADS, and then there is another one that uses QUAD_STRIP and TRIANGLE_STRIP.

Go to http://141.217.140.88/miguel/ and get them…

I hope this help…