user236520
user236520

Reputation:

Reversed triangle strip (winding issues) when drawing concatenated triangle strips (ios 6)

I am trying to send a pair of triangle strips, derived from input triangles, for rendering

The strips are defined by the following vertex indices:

strip 1: 0 14 16 15 1 23 30 41 8
strip 2: 31 7 17 18 16 0

  14______15______23______41            7 ______18______0
  / \    /  \    /  \    /  \          /  \    /  \    /
 /   \  /    \  /    \  /    \        /    \  /    \  /
0-----16------1 ------30------8     31------17------16

These strips are derived from the following triangles of indices (that in turn come from an arbitrary mesh). I use a positive sign to indicate that the triangle has the same winding in the strip compared to the input triangle.

Strip 1 input triangles
0 14 16 +
14 15 16 -
1 16 15 +
1 15 23 -
1 23 30 +
41 30 23 -
8 30 41 +

Strip 2 input triangles
7 17 31 +
7 18 17 -
16 17 18 +
0 16 18 -

If these triangles are rendered as triangles I get the expected results - a pair of triangle strips with the visible faces of the triangles all on the same side (in this case the visible faces are pointing toward the viewer).

If I render the strips individually as triangle strips, I get the expect results - identical to the result obtained by drawing triangles.

However, if I concatenate these strips following the apple guidelines (by duplicating the last vertex of the first strip and the first vertex of the second strip), the strips are drawn with strip 1 correct and strip 2 flipped (i.e. visible side reversed).

  14______15______23______41                     7 ______18______0
  / \    /  \    /  \    /  \                   /  \    /  \    /
 /   \  /    \  /    \  /    \                 /    \  /    \  /
0-----16------1 ------30------8----8----31----31------17------16

Strip sequence passed to renderer: 0 14 16 15 1 23 30 41 8 8 31 31 7 17 18 16 0

Finally the trivial experiment of reversing the second strip and passing the new sequence strip to the renderer makes no difference - the second strip is still flipped.

What have I missed?

Upvotes: 1

Views: 1046

Answers (1)

HalR
HalR

Reputation: 11083

What you are missing is "winding order". Winding order determines which way the triangle faces. Clockwise triangles face the direction opposite of CounterClockwise triangles.

When processing triangle strips, opengl "flips" the winding order for even numbered triangles. Otherwise you would get every other triangle facing the wrong direction.

Your concatenation theory is failing in practice because your first set of tri's contains an odd number of triangles.

In your case, it is easily remedied. Start with the second set first, as it has an even number of vertices/triangles.

In the general case, I think you would need to add an additional redundant triangle at the end of your first strip to give it an even number of triangles before adding the second set.

Upvotes: 1

Related Questions