OpenGL basic Primitives converted to Gl_triangles

Source: Internet
Author: User
1. Introduction

In OpenGL, basic primitives are the basic elements that make up the geometry, and OpenGL has some variations in the supported primitive types during version development. 2. Primitive types 2.1 OpenGL 2.1 supported primitive types

OpenGL 2.1 is the OpenGL Legecy, which supports 10 kinds of primitive types:

Gl_points       //Point
gl_lines        //Segment
Gl_line_strip//   Multi-segment Gl_line_loop//    coil
Gl_ Triangles    //triangle
gl_triangle_strip//triangular stripe
gl_triangle_fan   //triangular fan
gl_quads          //Quad
Gl_quad_strip     //quad stripe
gl_polygon        //polygon (convex)

These types are also the types that we used in OpenGL immediate mode (the type enumeration value specified in the Glbegin function) 2.2 OpenGL 3.3 supported primitive types

In OpenGL 3.3 (core profile), the primitive types that might be inefficient in previous versions were streamlined, and new types were added to match the shading language, including the following:

Gl_points
gl_line_strip
gl_line_loop
gl_lines
* * gl_line_strip_adjacency *
* gl_lines_ adjacency * *
gl_triangle_strip
gl_triangle_fan
gl_triangles
* * gl_triangle_strip_adjacency *
* * gl_triangles_adjacency * *
(indicates new type)

The types of quads and polygons are removed compared to the previous version (since quads and polygons do not guarantee that all the points that make up their polygons must be coplanar), and some of the geometry types that are applied in Geomtry shader OpenGL 4.5 support primitive Types

The primitive types supported in the latest version of OpenGL 4.5 are basically consistent with 3.3, adding an entry as follows:

Gl_points
gl_line_strip
gl_line_loop
gl_lines
gl_line_strip_adjacency
gl_lines_adjacency 
Gl_triangle_strip
Gl_triangle_fan
gl_triangles
gl_triangle_strip_adjacency
gl_triangles_adjacency
* * * GL_ Patches * * * * * * *
for new types
3. Triangulation of elements

In the analysis of the model algorithm, the model sometimes requires to be set to Gl_triangles type, the triangle type is relatively simple and intuitive, the following is how to convert the basic geometry type to a triangle to do some instructions.

With regard to transitions to triangles, a class has been provided in OpenSceneGraph, which is a type that Osg::trianglefunctor 3.1 cannot convert

The following types cannot be converted to gl_trianlges (or have no meaning after conversion)
1. gl_points
2. Gl_lines
3. Gl_line_strip
4. Gl_line_loop 3.2 Gl_triangle_strip

The first thing to understand is the composition of the Gl_triangle_strip, which is made up of at least 3 points (exactly 3 points is a gl_triangle), each adding a point, the new point will be and the previous two points of the existing structure of the triangle, and so on. In other words, when the triangular strip (Gl_triangle_strip) is composed of n points, the number of triangles is n-2 "the same case triangles the number of triangles is N/3", you can see when there are a large number of points common, triangular bands can save a lot of storage space compared to triangles. The exact composition is shown in the following figure:

Assuming the coordinate sequence number of the starting point is 0 and the new point is incremented sequentially, the conversion algorithm is as follows:
1. Cannot form triangular bands when all points are less than or equal to 2 o'clock
2. The dot number starting from 0, (dot N) is an even number, the formation of the triangle is [N, N+1, n+2]
3. The dot number starting from 0, (dot n) is odd when the composition of the triangle is [N, n+2, n+1] 3.3 gl_quads

The quadrilateral is converted to a triangle, and each quadrilateral is converted to two triangles, assuming that the four points that make up the quadrilateral are [N, n+1, n+2, N+3], and the two triangles after the conversion are:
1. [N, N+1, n+2]
2. [N, N+2, n+3] 3.4 gl_quad_strip

The quadrilateral strips are shown in the following figure:


The rules drawn in this way are as follows:
The starting edge of the first quadrilateral is determined by the first two points in the vertex array, and the vector direction of the edge is determined by the direction of the two-point extension; the opposite edge of the starting edge is determined by the two subsequent points in the vertex array, and if the starting and opposite vectors are different, the quadrilateral is distorted (that is, the correct quadrilateral bands The direction of each of the two points is consistent) the direction in which the starting edge is drawn thereafter is determined by the previous paragraph. (Refer to the above image, the first edge of the above point is V0, the following point is V1, then V2 and v3 order is v2 on, V3 in the next). The algorithm for converting to triangles is:

Assuming that the current point number is n, then the triangle is
[N, N+1, n+2]
[N+1, N+3, n+2]
increments two points at a time, and then continues to generate two triangles
3.5 Gl_triangle_fan and Gl_polygon

The triangle fan is converted in a common vertex, as shown in the following figure:

When converting to a triangle, the first vertex is pooled, so the transformed triangle needs to be [V0, V1, v2] [v0,v2,v3] [V0, V3, V4]

Polygon in the process of the transformation of a lot of, triangular fan This conversion method also applies to the polygon conversion, the conversion algorithm is as follows:

The dot number starts at 2 and increments by 1, creating a new triangle until the last vertex. Assuming that the current point number is N, the triangle is composed of [V0, VN, vn+1]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.