Triangle strip and degenerate triangles
Asked Answered
D

2

6

My question could be stupid but I didn't find good example of triangle strip utilization:

https://i.sstatic.net/KL8jk.png

With vertices like that:

A: -0.5f, -0.5f,  // Bottom left.
B: -0.5f,  0.5f,  // Top left.
C:  0.5f, -0.5f,  // Bottom Right.
D:  0.5f,  0.5f   // Top right.
----------------------------------
B--D
|\ |
| \|    
A--C    

Sometimes, in examples, we can find this configuration:

  • A, B, C, C, B, D

or this:

  • A, B, C, D

What is right? I've tried both and both works.

Now I would like to use degenerate triangle to merge two square.

B--D    F--H    
|\ |    |\ |    
| \|    | \|    
A--C    E--G    

Here is what I've got:

ABCD + DEEF + EFGH

But here again, I've got some artifacts sometimes.

Danieladaniele answered 10/9, 2013 at 9:46 Comment(1)
Can you describe / screenshot the artifacts you get in case "ABCD + DEEF + EFGH"? It looks correct, even though there are solutions with fewer degenerate triangles.Jenevajeni
C
4

If you use backface culling, the two configurations would not produce the same result. In the ABCD case, BCD is counterclockwise, whereas in the ABCCBD case, CBD is counterclockwise. The right way to draw two quads would depend on whether you care about orientation. I would suggest ABCDDEEFGH.

Chil answered 10/9, 2013 at 20:32 Comment(0)
J
4

I personally don't think writing separate patches in one triangle strip makes code easy to write or easy to understand. If you can't measure a performance difference, I would advice to use solution A or B.

Solution A: Send two separate triangle strip drawing commands

drawElements(TRIANGLE_STRIP, [A, B, C, D]);
drawElements(TRIANGLE_STRIP, [E, F, G, H]);

Solution B: Send one GL_TRIANGLES command with two separate patches

drawElements(TRIANGLES, [A, B, C, 
                         C, B, D,
                         E, F, G,
                         G, F, H]);

Solution C: The Triangle Strip solution you have asked for

drawElements(TRIANGLE_STRIP, [A, B, C, D, 
                              D, E,
                              E, F, G, H]);

Solution C draws triangles

.A B C
 C B D
.C D D - deg
 D D E - deg
.D E E - deg
 E E F - deg
.E F G
 G F H
Jenevajeni answered 10/9, 2013 at 10:29 Comment(0)
C
4

If you use backface culling, the two configurations would not produce the same result. In the ABCD case, BCD is counterclockwise, whereas in the ABCCBD case, CBD is counterclockwise. The right way to draw two quads would depend on whether you care about orientation. I would suggest ABCDDEEFGH.

Chil answered 10/9, 2013 at 20:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.