Triangular strip and degenerate triangles

My question may be silly, but I did not find a good example of using a triangle strip:

http://i.stack.imgur.com/KL8jk.png

With such vertices:

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 the examples we can find this configuration:

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

or that:

  • A, B, C, D

What is right? I tried both and both work.

Now I would like to use a degenerate triangle to merge two squares.

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

Here is what I have:

ABCD + DEEF + EFGH

But then again, I sometimes have artifacts.

+6
source share
2 answers

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

+4
source

I personally don’t think that writing separate patches in the same strip of a triangle makes the code easy to write or easy to understand. If you cannot measure the difference in performance, I would recommend using solution A or B.

Solution A: Send two separate triangle strip 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 requested

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

Solution C draws triangles

 .ABC CBD .CDD - deg DDE - deg .DEE - deg EEF - deg .EFG GFH 
+3
source

Source: https://habr.com/ru/post/953550/


All Articles