Sign in to follow this  
vagra

How can i convert a GL_TRIANGLE_STRIP to GL_TRIANGLES?

Recommended Posts

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


Link to 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


Link to 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


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this