Questions tagged [gl-triangle-strip]

A triangle strip is a series of connected triangles, sharing vertices, allowing for faster rendering and more efficient memory usage for computer graphics. In OpenGL implementation, GL_TRIANGLE_STRIP draws a series of triangles using vertices v0, v1, v2, then v2, v1, v3 (note the order), 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

A triangle strip is a series of connected triangles, sharing vertices, allowing for faster rendering and more efficient memory usage for computer graphics. They are optimized on most graphics cards, making them the most efficient way of describing an object. There are two primary reasons to use triangle strips:

  • Triangle strips increase code efficiency. After the first triangle is defined using three vertices, each new triangle can be defined by only one additional vertex, sharing the last two vertices defined for the previous triangle.
  • Triangle strips 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.

OpenGL implementation

OpenGL has innate support for triangle strips using the glBegin(), glVertex*(), and glEnd() functions. To draw a triangle strip, glBegin() must be passed the argument GL_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.

//Vertices below are in Clockwise orientation
//Default setting for glFrontFace is Counter-clockwise
glFrontFace(GL_CW);

glBegin(GL_TRIANGLE_STRIP); 
glVertex3f( 0.0f, 0.0f, 0.0f ); //vertex 1
glVertex3f( 0.0f, 1.0f, 0.0f ); //vertex 2
glVertex3f( 1.0f, 0.0f, 0.0f ); //vertex 3
glVertex3f( 1.5f, 1.0f, 0.0f ); //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.

Quoted directly from the OpenGL Programming Guide:

GL_TRIANGLE_STRIP Draws a series of triangles (three-sided polygons) using vertices v0, v1, v2, then v2, v1, v3 (note the order), 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.

65 questions
38
votes
2 answers

GL_TRIANGLE_STRIP vs GL_TRIANGLE_FAN

I need an example of a polygon that can be done only by GL_TRIANGLE_STRIP and another polygon that can be done only by GL_TRIANGLE_FAN.
tiggares
  • 475
  • 1
  • 5
  • 10
28
votes
4 answers

Generate a plane with triangle strips

What would be the best algorithm to generate a list of vertices to draw a plane using triangle strips? I'm looking for a function which receives the plane's width and height and returns a float array containing correctly indexed vertices. width…
NIGO
  • 863
  • 2
  • 10
  • 16
25
votes
2 answers

What's the de facto standard of triangle winding direction in OpenGL?

We have two options in triangle winding direction, clock-wise counter-clockwise Anyway converting between them could take some cost. I want to avoid conversion as much as possible, and to do that, I need to know de facto standard of winding…
eonil
  • 83,476
  • 81
  • 317
  • 516
21
votes
6 answers

Cube using single GL_TRIANGLE_STRIP

Is it possible to draw a whole cube using just a single GL_TRIANGLE_STRIP? Obviously it's just the cube combinatorics I'm concerned about here, it might as well be stretched into any kind of box or similar object.
MvG
  • 57,380
  • 22
  • 148
  • 276
9
votes
1 answer

Problem with degenerate triangles and GL_TRIANGLE_STRIP

I'm trying to draw multiple triangle strips with only one call to glDrawElements and my research on the matter tells me I need to use degenerate triangles. Maybe my understanding on the subject is wrong but I thought this should allow me to "jump"…
rfgamaral
  • 16,546
  • 57
  • 163
  • 275
8
votes
2 answers

Polygon triangulation into triangle strips for OpenGL ES

I am looking for a fast polygon triangulation algorithm that can triangulate not very complex 2D concave polygons (without holes) into triangle strips ready to be sent to OpenGL ES for drawing using GL_TRIANGLE_STRIP. I am aware of some algorithms…
8
votes
2 answers

OpenGL: Problem with triangle strips for 3d mesh and normals

I'm new to opengl programing. I'm currently making animation of cave shaft formation. I have a set of coordinats for profiles of the shaft along the z-axis. My plan is to make a 3d mesh from this data and to do that I've decieded to use…
Diba
  • 81
  • 1
  • 2
8
votes
1 answer

Indexed GL_TRIANGLES vs. indexed GL_TRIANGLE_STRIP

There has been quite a buzz about rendering performance between indexed triangles or triangle strips. But I believe there is a case that has not been considered enough. Indexed triangles are rendered like this in OpenGl: glDrawElements(GL_TRIANGLES,…
user2464424
  • 1,536
  • 1
  • 14
  • 28
7
votes
2 answers

Does the winding direction in an OpenGL triangle strip alternate from triangle to triangle?

I'm trying to clear up some inconsistencies I'm seeing in triangle strip vertex winding direction (clockwise and counter-clockwise). I'm drawing a trapezoid rotated 90 degrees counter-clockwise in OpenGL. Here's the relevant code: unsigned char…
charon00
  • 109
  • 1
  • 5
7
votes
1 answer

Is It More Efficient to Use GL_TRIANGLE_STRIP or Indexed GL_TRIANGLES to a Draw a Dynamic Number of Quads

I'm developing a simple sprite-based 2D game in C++ that uses OpenGL for hardware-accelerated rendering, and SDL for window management and user input handling. Since it's a 2D game, I'm only ever going to need to draw quads, but because the number…
BitsOfBytes
  • 85
  • 2
  • 7
6
votes
2 answers

Triangle strip and degenerate triangles

My question could be stupid but I didn't find good example of triangle strip utilization: https://i.stack.imgur.com/KL8jk.png With vertices like that: A: -0.5f, -0.5f, // Bottom left. B: -0.5f, 0.5f, // Top left. C: 0.5f, -0.5f, // Bottom…
LongDuZboub
  • 1,041
  • 2
  • 12
  • 18
4
votes
1 answer

add visual below finger swipe, Triangle strip like fruit ninja Andengine

I want to show a triangle strip when user swap finger on screen. I am not sure how to do it with AndEngine, using particle system or using sprites or using Triangle Strip algo... I haven't wrote any code because I am struck that what to do. I am…
AZ_
  • 21,688
  • 25
  • 143
  • 191
4
votes
1 answer

graph - How to construct a graph for triangular strips in linear time even for worst case?

In Graph, there is a triangular strip problem. Basically, we have a set of adjacent triangles and we want to consider each triangle as a new vertex and there will be an edge between two new vertices if the two triangles behind them have an edge in…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
3
votes
2 answers

Help getting vertex indices from a grid

I'm folloing this little tutorial on how to get indices from a grid to build a GL_TRIANGLE_STRIP mesh http://dan.lecocq.us/wordpress/2009/12/25/triangle-strip-for-grids-a-construction/ I'm getting some of the indices in the right order but I can't…
Ricardo Sanchez
  • 4,935
  • 11
  • 56
  • 86
3
votes
1 answer

Is there a way to implement something like marching squares on a grid drawn with triangle strips?

I am currently drawing a grid using a series of triangle strips. I am using this to render a height field, and generating the vertex data completely in the vertex shader without any input buffers just using the vertex and instance indexes. This is…
Dag Ågren
  • 1,064
  • 7
  • 18
1
2 3 4 5