How does gl triangle fan work




















Note: The image examples uses clockwise winding order, while in OpenGL the front side uses counter-clockwise winding order , i. This is an important detail if face culling is enabled. 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. And here I'm modifying some vertex height:. In 2D and without holes, this is fairly easy. First, you need to break your polygon to one or more monotone polygons.

The monotone polygons are pretty simple to turn into tristrips, just sort the values by y , find the top-most and bottom-most vertex, and then you have lists of vertices to the right and to the left because vertices come in some defined, say clockwise, order.

Then you start with top-most vertex and add vertices from the left and from the right sides in alternating manner. This technique will work for any 2D polygons without self-intersecting edges, which includes some cases of polygons with holes the holes must be correctly wound though. This code is not optimal, but it should be easy to understand. At the beginnig, a concave polygon is created. Then a "working set" of vertices is created. On that working set, a permutation is calculated which sorts the vertices by their y coordinate.

That permutation is then looped through, looking for split points. Once a split point is found, a new monotone polygon is created. Then, the vertices used in the new polygon are removed from the working set and the whole process repeats. Once the stream is processed by the vertex shader, it must be interpreted into something meaningful by OpenGL.

This parameter is called the rendering mode or primitive. The parameter actually determines two things. The first it determines is what kind of things the vertex stream refers to; this is the primitive type. OpenGL can render points and lines in addition to triangles. These are all different primitive types. The other thing the parameter determines is how to interpret the vertex stream for that primitive type. This is the primitive representation. The numbers represent vertices in the vertex stream, not indexed rendering indices.

Among other things, this means that the vertex stream must have a length divisible by 3. There are two other triangular primitive representations. They are both used in the cylinder mesh, so let's take a look at that. This primitive has the triangle primitive type, so this vertex stream will generate triangles. But it will generate them using a different representation. Then, for every vertices and its next vertex, a triangle is made out of these two plus the initial vertex.

Visually, a triangle fan looks like this:. The numbers represent the order that the vertices are in in the vertex stream. The red line shows the triangle edges that are directly specified by the vertex stream.

And if you just wanted to know if it was kept, the specification and documentation all tell you that. The 3. Add a comment. Active Oldest Votes. Improve this answer. You probably need a triangle strip instead of a fan. 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. 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. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.

Email Required, but never shown.



0コメント

  • 1000 / 1000