Jump to content

  • Log In with Google      Sign In   
  • Create Account


glxy

Member Since 28 Sep 2012
Offline Last Active Sep 28 2012 01:54 AM
-----

Posts I've Made

In Topic: Quick confirmation on Triangle Strips / Degenerate Triangles

28 September 2012 - 01:01 AM

Say you've got 2 strips, strip 1 has vertexes 0, 1, 2, 3 and strip 2 has vertexes 4, 5, 6, 7. To render them with GL_TRIANGLES you use indexes 0, 1, 2, 1, 3, 2, 4, 5, 6, 5, 7, 6 for your glDrawElements call. No need to make any changes to the vertexes. That'll do it.

The number of indexes you need for each strip is always (numverts - 2) * 3 and just remember to follow the winding order rules, reversing the order for alternate tris that make up the strip. Code for writing out indexes might look something like this:

for (int i = 2; i < stripverts; i++)
		{
			indexes[totalindexes++] = totalverts + i - 2;
			indexes[totalindexes++] = (i & 1) ? (totalverts + i) : (totalverts + i - 1);
			indexes[totalindexes++] = (i & 1) ? (totalverts + i - 1) : (totalverts + i);
		}

		totalverts += stripverts;

Then just ensure that all of your vertexes for all strips are in a single big array (or single VBO, as appropriate) and your draw call is:

glDrawElements (GL_TRIANGLES, totalindexes, GL_UNSIGNED_WHATEVER, indexes); // _WHATEVER is _SHORT or _INT, replace indexes with 0 for a VBO

OK, it's more indexes, but indexes are much smaller than full vertexes, the duplicate vertexes will be in your cache and so won't need to be retransformed, and you'll find that the overall submission is lighter than with degenerate triangles.

do u have any sample code i m begiiner in open gl

In Topic: Quick confirmation on Triangle Strips / Degenerate Triangles

28 September 2012 - 12:53 AM

any one have sample code for triangle strip

PARTNERS