Jump to content
• Advertisement

# How can i convert a GL_TRIANGLE_STRIP to GL_TRIANGLES?

This topic is 4417 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

i'm a beginer, can you help me?

#### Share this post

##### Share on other sites
Advertisement
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 this post

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

#### Share this post

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

#### Share this post

##### Share on other sites
@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 this post

##### Share on other sites
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;}

#### Share this post

##### Share on other sites

• Advertisement

### Announcements

• Advertisement
• ### Popular Tags

• Advertisement

• 16
• 11
• 9
• 49
• 12
• ### Forum Statistics

• Total Topics
631392
• Total Posts
2999738
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!