5

I am learning openGL, and i have come across triangle fans using vertex buffer objects. If given an array of vertices to render, how does openGL decide how many of those vertices must be used to construct a triangle fan. It seems like an arbitray number of the vertices could be used.

Popgalop
  • 737
  • 2
  • 9
  • 26

4 Answers4

11

This can easily be explained by comparing Triangle Strips with Triangle Fans.

Triangle Strip

As you probably know, a Triangle Strip is a set connected triangles which share vertices, this allows for more efficient memory usage. (We save memory because we don't store all duplicated vertices)

Example of a Triangle Strip

enter image description here

Triangle Fan

On the other hand we have a Triangle Fan, this is also a set of connected triangles. Though all these triangles have one vertex in common, which is the central vertex. (The first vertex is always the center)

With that said we can take the same image above and change the order of the vertices. When that done the Triangle Fan would look like this. (Where A, is the first and central vertex)

Example of a Triangle Fan

enter image description here

In the image above the Triangle Fan will only work in the colored area, because of how the vertices need to be arranged according to be a Triangle Fan.

vallentin
  • 23,478
  • 6
  • 59
  • 81
  • 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 fan](https://en.wikipedia.org/wiki/Triangle_fan) – ToolmakerSteve Sep 09 '14 at 04:57
5

Visually, this is how a triangle fan works:

Each triangle shares the central vertex A, and re-uses the last vertex addressed. Thus after defining ABC each following triangle only requires 1 point (e.g. D, E, F).

Indices:     A,B,C,D,E,F     [Count: 6]
Triangles:  (A,B,C)
            (A) (C,D)
            (A)   (D,E)
            (A)     (E,F)    [N=4]  -->  4+2 = 6

Another way of thinking about this is that each triangle shares an edge radiating from a central vertex with the prior triangle; literally like a folding a paper fan.

      Paper fan

You need N+2 vertices, where N is the number of triangles in your fan.

Community
  • 1
  • 1
Andon M. Coleman
  • 42,359
  • 2
  • 81
  • 106
3

Look here: GL_TRIANGLE FAN Explanation

The more vertices you give to openGL, the more triangles you get. The first vertex will be common to all triangles. First triangle consists of the vertices 1, 2 and 3. Second triangle consists of 1, 3 and 4. And so on. You get n - 2 triangles for n vertices.

Community
  • 1
  • 1
user1781290
  • 2,674
  • 22
  • 26
2

That is specified by the command which you use to do the rendering. For example both drawArrays() and drawElements() have a count parameter which specifies the number of vertices to use.

Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455