A triangle strip is a series of connected triangles from the triangle mesh, sharing vertices, allowing for more efficient memory usage for computer graphics. They are more efficient than triangle lists without indexing, but usually equally fast or slower than indexed triangle lists. The primary reason to use triangle strips is to reduce the amount of data needed to create a series of triangles. The number of vertices stored in memory is reduced from 3N to N+2, where N is the number of triangles to be drawn. This allows for less use of disk space, as well as making them faster to load into RAM. For example, the four triangles in the diagram, without using triangle strips, would have to be stored and interpreted as four separate triangles: ABC, CBD, CDE, and EDF. However, using a triangle strip, they can be stored simply as a sequence of vertices ABCDEF. This sequence would be decoded as a set of triangles with vertices at ABC, BCD, CDE and DEF - although the exact order that the verticies are read will not be in left-to-right order as this would result in adjacent triangles facing alternating directions.
has built-in support for triangle strips. Fixed function OpenGL has support for triangle strips using immediate mode and the glBegin, glVertex*, and glEnd functions. Newer versions support triangle strips using glDrawElements and glDrawArrays. To draw a triangle strip using immediate mode OpenGL, glBegin must be passed the argumentGL_TRIANGLE_STRIP, which notifies OpenGL a triangle strip is about to be drawn. The glVertex* family of functions specify the coordinates for each vertex in the triangle strip. For more information, consult The OpenGL Redbook. To draw the triangle strip in the diagram using immediate mode OpenGL, the code is as follows: //Vertices below are in Clockwise orientation //Default setting for glFrontFace is Counter-clockwise glFrontFace; glBegin; glVertex3f; //vertex 1 glVertex3f; //vertex 2 glVertex3f; //vertex 3 glVertex3f; //vertex 4 glEnd;
Note that only one additional vertex is needed to draw the second triangle. In OpenGL, the order in which the vertices are specified is important so that surface normals are consistent. Quoting directly from the OpenGL Programming Guide:
GL_TRIANGLE_STRIPDraws a series of triangles using vertices v0, v1, v2, then v2, v1, v3, then v2, v3, v4, and so on. The ordering is to ensure that the triangles are all drawn with the same orientation so that the strip can correctly form part of a surface.
It's even clearer within the manual pages:
Draws a connected group of triangles. One triangle is defined for each vertex presented after the first two vertices. For odd n, vertices n, n+1, and n+2 define triangle n. For even n, vertices n+1, n, and n+2 define triangle n. N-2 triangles are drawn.
The above code sample and diagram demonstrate triangles drawn in a clockwise orientation. For those to be considered front-facing, a preceding call to glFrontFace is necessary, which otherwise has an initial value of GL_CCW. This is significant if glEnable and glCullFace are already active, because back-facing triangles will be culled, so will not be drawn and will not appear on-screen at all.
Properties and construction
It follows from definition that a subsequence of vertices of a triangle strip also represents a triangle strip. However, if this substrip starts at an even vertex, then the resulting triangles will change their orientation. For example a substrip BCDEF would represent triangles: BCD,CED,DEF. Similarly, reversal of strips’ vertices will result in the same set of triangles if the strip has an even number of vertices.. Converting a general polygon mesh to a single long strip was until recently generally not possible. Usually the triangle strips are analogous to a set of edge loops, and poles on the model are represented by triangle fans. Tools such as Stripe or FTSG represent the model as several strips. Optimally grouping a set of triangles into sequential strips has been proven NP-complete. Alternatively, a complete object can be described as a degenerate strip, which contains zero-area triangles that the processing software or hardware will discard. The degenerate triangles effectively introduce discontinuities or "jumps" to the strip. For example, the mesh in the diagram could also be represented as ABCDDFFEDC, which would be interpreted as triangles ABC CBD CDD DDF DFF FFE FED DEC. Notice how this strip first builds two triangles from the left, then restarts and builds the remaining two from the right. While discontinuities in triangle strips can always be implemented by resending vertices, APIs sometimes explicitly support this feature. IRIS GL supported Swaps, a feature relied on by early algorithms such as the SGI algorithm. Recently OpenGL/DirectX can render multiple triangle strips without degenerated triangles using Primitive Restart feature.