# How can i convert a GL_TRIANGLE_STRIP to GL_TRIANGLES?

## Recommended Posts

vagra    122
i'm a beginer, can you help me?

##### Share on other sites
Kalasjniekof    246
Let me explain it with an image:

A triangle-strip is constructed like this:
create a triangle from v1, v2, v3
create a triangle from v2, v3, v4
...
create a triangle from v5, v6, v7
Do you see the pattern?

In code it would be something like:
int numberOfVerticesInTriangleStrip = 7;Vertex[7] triangleStrip;int pos = 0;while(pos <= numberOfVerticesInTriangleStrip - 2){    Triangle tri;    tri.v1 = triangleStrip[pos];    tri.v2 = triangleStrip[pos + 1];    tri.v3 = triangleStrip[pos + 2];    pos++;}

With a Vertex, I mean a struct containing a postion (x,y,z)
With a Triangle, I mean a struct containing three Vertex.

Obviously this won't compile, but it should give you something to get started with.

Good luck!

##### Share on other sites
vagra    122
thank you very much! thanks!

##### Share on other sites
Trienco    2555
Maybe I'm just not seeing it, but shouldn't you also reverse the winding order of every second triangle?

##### Share on other sites
Kalasjniekof    246
@Trienco: You're right, I didn't think of that! Something like this should work, right?

while(pos <= numberOfVerticesInTriangleStrip - 3){    Triangle tri1;    tri1.v1 = triangleStrip[pos];    tri1.v2 = triangleStrip[pos + 1];    tri1.v3 = triangleStrip[pos + 2];    Triangle tri2;    tri2.v1 = triangleStrip[pos + 2];    tri2.v2 = triangleStrip[pos + 1];    tri2.v3 = triangleStrip[pos + 3];    pos++;}

##### Share on other sites
vagra    122
thanks! i white a code like this:

void buildTriangleList(void){    gTriangleNum = gTriangleStripNum - 3 + 1;    g_pTriangleIndices = new GLuint[gTriangleNum * 3];    for (int i=0; i<gTriangleNum; i++)    {        if ((i%2)==0)        {            g_pTriangleIndices[i*3+0]    = g_pTriangleStripIndices[i + 0];            g_pTriangleIndices[i*3+1]    = g_pTriangleStripIndices[i + 1];            g_pTriangleIndices[i*3+2]    = g_pTriangleStripIndices[i + 2];        }        else        {            g_pTriangleIndices[i*3+0]    = g_pTriangleStripIndices[i + 2];            g_pTriangleIndices[i*3+1]    = g_pTriangleStripIndices[i + 1];            g_pTriangleIndices[i*3+2]    = g_pTriangleStripIndices[i + 0];        }    }    return;}