17

I am trying to "fill" a surface of a sphere that I drew using this algorithm here: http://paulbourke.net/miscellaneous/sphere_cylinder/, the first method.

I know that GL_QUADS is no longer used in OpenGL 3+. SO I used GL_TRIANGLE_FAN. Is it the same thing? The problem here is that my sphere facets are squares. So if I use GL_TRIANGLE then I get a weird "filling", not all the surface is covered.

Am I doing it the wrong way? How does GL_TRIANGLE_FAN work exactly?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Trt Trt
  • 5,330
  • 13
  • 53
  • 86
  • is that for new versions of OpenGL? – Trt Trt Nov 07 '11 at 23:10
  • Triangle FAN is a basic primitive which share the same concept in all OpenGL versions and also Direct3D (XNA). – stefan Nov 07 '11 at 23:13
  • @TrtTrt: New version? OpenGL removed features; it didn't _change_ the ones it kept. And if you just wanted to know if it was kept, the specification and documentation all tell you that. The [3.3](http://www.opengl.org/sdk/docs/man3/) and [4.2](http://www.opengl.org/sdk/docs/man4/) documentation is _only_ for core OpenGL. – Nicol Bolas Nov 08 '11 at 00:22

2 Answers2

69

How does GL_TRIANGLE_FAN works exactly?

The first vertex of a triangle fan acts like a hub. The vertices following connect with the previous non-starting vertex and the hub.

enter image description here

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Is it counter clockwise in every ‚common’ implementation? (Webgl for example) – LuckyLuke Skywalker Sep 17 '22 at 14:53
  • 1
    The winding order is not so much a thing about the primitive (which this question was about), but what's interpreted as the front face of a primitive. And you can switch that per your requirements. As far as Khronos graphics APIs go the *default* for OpenGL, OpenGL-ES and WebGL is counterclockwise. Vulkan doesn't have a default and face orientation winding rule must be set explicitly at pipeline creation. – datenwolf Sep 18 '22 at 08:43
0

You probably need a triangle strip instead of a fan.

See also this question: gl_triangle_strip vs gl_triangle_fan

Kris Van Bael
  • 2,842
  • 1
  • 18
  • 19
  • 3
    I doubt that a triangle strip would help him to tessellate a sphere in one draw call. And for a single quad a triangle fan works as well as a triangle strip. – Christian Rau Nov 07 '11 at 23:52
  • 1
    You can use a triangle strip, but you need to strategically duplicate vertices at the end of the strip to move to the next strip. The duplicated vertices create empty triangles, which OpenGL ignores. However, using straight-up triangles is certainly more straightforward. – prewett Nov 15 '17 at 23:51