GL_TRIANGLE_STRIP vs GL_TRIANGLE_FAN
Asked Answered
D

2

40

I need an example of a polygon that can be done only by GL_TRIANGLE_STRIP and another polygon that can be done only by GL_TRIANGLE_FAN.

Deservedly answered 5/12, 2013 at 8:15 Comment(0)
C
76

When knowing the difference between Triangle Strip and Triangle Fan a shape will be easy to make.

Triangle Strip

For instance a Triangle Strip is a set of connected triangles which share vertices.

Example of Triangle Strip

Using Triangle Strip we will be able to get the following output, using those given vertices.

enter image description here

Triangle Fan

Where a Triangle Fan is also a set of connected triangles, though all these triangles have a common vertex, which is the central vertex.

In OpenGL the central vertex is the first given vertex, in the Triangle Fan.

Example of Triangle Fan

Using Triangle Fan and the same vertices as in the other example, we will only be able to get the colored area as output. That is due to the importance of the arranged order of the vertices in Triangle Fan. Basically, all the vertices need to go around the central vertex.

enter image description here

Conclusion

As you can see on our 2 example sets of vertices those "output shapes" are unique to both Triangle Strip and Triangle Fan.

Note: The image examples uses clockwise winding order, while in OpenGL the front side uses counter-clockwise winding order, i.e. the examples are literally facing away from the camera. This is an important detail if face culling is enabled.

Extra

I made a similar answer here, you can read it if you want, I actually used the same images since the questions are closely related.

Contraception answered 5/12, 2013 at 8:23 Comment(4)
Is a fan drawn faster than a strip?Terbium
A better explanation is that the strip always uses the last 2 vertices of one triangle as the first 2 vertices of the next triangle. So in the strip diagram, imagine doing the first 3 triangles, then wanting to add a triangle C-E-G instead of D-E-G. Can't do that, because D-E is automatically the start of triangle 4. The result can be done with a fan, as there is a common vertex. Diagram of the result: Wiki- Triangle fanBesse
Your drawings have a clockwise ordering of the first triangle, which may be a problem for a beginner OpenGL user. CW oriented triangles will not be drawn with default OpenGL settings.Fsh
@PaulJurczak Damn, 7 years and I never noticed that. I've updated the answer and added a comment, thanks :)Contraception
T
10

Difficult to answer in pure text. For Fan, an S shape would be impossible (in general, remember that fan is limited in that there is a point common to every triangle).

As for the other way around - it's a trick question. triangle_strip can do every triangle_fan polygon, although it requires a little trickery. Consider the following polygon (ordering shown is for triangle_fan)

3--4--5
|\ | /|
2--1--6
   | \|
   8--7

This could be done as follows

2-----4
| \  /|
1--3/7| 
   | \|
   6--5

Note the overlapping polygons. If you don't allow double-sided polys or overlap, then this would be an example of a fan only poly, I suppose.

Tullius answered 5/12, 2013 at 8:20 Comment(2)
thanks! it's a perfect example. I was not considering overlapping polygons, so its a valid example.Deservedly
As you said, there is no such thing as a fan-only poly for the simple reason that you can mimic a triangle fan using a triangle strip by repeating the common vertex every other vertex. If vertex 1 is to be the common vertex, do (1,)2,1,3,1,4,1,5,1,6, etc. Every other triangle is degenerate. (No need to specify that first "1" because the first triangle is a degenerate one.)Abvolt

© 2022 - 2024 — McMap. All rights reserved.