[OpenGL] Three ways to draw triangle sequences, such as gl_triangle_strip

Source: Internet
Author: User

The Method of Drawing triangles using gl_triangle_strip is often confusing. Here we will explain its operation mechanism.

Generally, there are three ways to draw a series of triangles: gl_triangles, gl_triangle_strip, and gl_triangle_fan.

As shown in:

Gl_triangles draws a triangle for each of three vertices. The first triangle uses vertices v0, V1, V2, and the second triangle uses V3, V4, V5, and so on. If the number of vertices N is not a multiple of 3, the last one or two vertices will be ignored.

Gl_triangle_strip is a little complicated.

The rule is:

The connection sequence for building the vertex of the current triangle depends on the parity of the sequence number of the current vertex of the triangle to be formed with the two vertices that have appeared before (if starting from 0 ):

If the current vertex is an odd number:

Order of the vertices in a triangle: t = [n-1 N-2 N].

If the current vertex is an even number:

The order of the vertices that make up the triangle: t = [N-2 n-21 N].

For example, if the first triangle and vertex v2 are 2 and an even number, the vertex order is v0, V1, and V2. In the second triangle, if the vertex V3 sequence is 3 and is an odd number, the vertex order is V2, V1, V3. In the third triangle, the vertex V4 sequence is 4, which is an even number, the order of vertices is V2, V3, V4, and so on.

This order is used to ensure that all triangles are drawn in the same direction, so that the triangle string can correctly form a part of the surface. For some operations, maintenance is very important, such as elimination.

Note: The number of vertices n must be at least 3; otherwise, no triangle can be drawn.

Gl_triangle_fan is similar to gl_triangle_strip, but its triangle vertices are arranged in the order t = [n-1 N-2 N]. Each triangle forms a slice sequence.

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.