Correct usage GL_TRIANGLE_STRIP

Hello,

I have some problems using GL_TRIANGLE_STRIP. I want to create several stripes and put them together side by side.

It’s like this:

0 1 2

3 4 5

6 7 8

The numbers represent vertices being arranged in an array in that order.

Now I want to know in which order I have to draw these vertices when using GL_TRIANGLE_STRIP to get the 8 triangles computed. The result shall be an even ground with 4 edges.

Gl.glBegin(Gl.GL_TRIANGLE_STRIP);
Gl.glVertex3f(....);
....
Gl.glEnd();  

Thanks in advance.

You’ll actually need 2 triangle strips.
A triangle strip is something like this:

0-2-4-6-8  =>
|/|/|/|/|  =>
1-3-5-7-9  =>

So, in your case you need:

0-1-2
|/|/|
3-4-5
and
3-4-5
|/|/|
6-7-8

The order would be:
0, 3, 1, 4, 2, 5 for first strip and
3, 6, 4, 7, 5, 8 for second strip

Hey,

before posting my problem I did connect the vertices exactly in the order you adviced me. But the result looked quite strange. May be my code is wrong?

For every new strip I am using a new glBegin(GL_TRIANGLE_STRIP) and glEnd() block. Therefore I am using two code blocks for the example above.

Is that okay?

Well, i checked my code with debug and realized, that my index array was built wrongly.

I’ll check it.

Uff … it’s difficult for me to find a suitable algorithm to fill my index array with the correct numbers, if the number of points is variable:

For 3 points at each side the order is 0, 3, 1, 4, 2, 5, 3, 6, 4, 7, 5, 8 (as you described).

For 4 points it is another order:
0, 4, ,1 ,5 ,6 ,2, 7, 3, 5, 8 ,5, 9, 6, 10, 7, 11, 8, 12, 9, 13, 10, 14, 11, 15.

On first attempt I tried to fill the index array in 2 steps. First every even position and then every odd position. But it doesn’t work for me …

Ok I solved it:

        for (int index = 0; index < pointArray.Length-sizeX; index++)
        {
            indexArray[index*2] = index;
            indexArray[index*2 + 1] = index + sizeX;
        }