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
0
votes
0 answers

How to optimize my drawing routine to rasterize triangles to the screen in Java

I'm currently programming a 3D software renderer where I am rasterizing triangles based on a function to take x and y coordinates to draw 3 lines to draw a triangle that works just fine. However, my code to interpolate through the triangle to fill…
Ryan C.
  • 1
  • 1
0
votes
0 answers

Why Doesn't My Heightmap-Generated Terrain Texture Correctly?

I'm building a heightmap out of a 2D array of shorts. The code to generate the vertices is MeshVertex v; // has position, normal, and texCoord fields v.position = glm::vec3( (float) x * 150, height * 64, (float) z * 150 ); When I…
Goldentoa11
  • 1,700
  • 2
  • 17
  • 29
0
votes
1 answer

How do I draw a rectangular box using GL_TRIANGLE_STRIP?

I'm new to OpenGL programming and need some help wrapping my head around this issue. I found this answer detailing how to create a cube mesh using a GL_TRIANGLE_STRIP. However, I want to create a rectangular box where the one axis isn't just…
Niklas
  • 465
  • 2
  • 9
  • 19
0
votes
1 answer

Opengl : Can we still use GL_QUADS?

I am loading models from obj, colladae files where individual faces of the mesh are not triangulated if all the faces are perfect quads when exporting to save memory. Now I know this won't work for most models but for some meshes say a cube where…
Sync it
  • 1,180
  • 2
  • 11
  • 29
0
votes
0 answers

WebGL TRIANGLE vs TRIANGLE_STRIP

I've got a single triangle rendering using gl.TRIANGLE_STRIP, but when I try to change it to gl.TRIANGLE, the faces do not render. It appears like the vertices are rendering as really tiny dots, but the faces are empty. My understanding is that the…
rich remer
  • 3,407
  • 2
  • 34
  • 47
0
votes
0 answers

Generate and draw a square plane with GL_TRIANGLES?

Preface: I have read the post over at Generate a plane with triangle strips. The code below is from there, however it does not allow me to texture or light the grid. Objective: Given a number 'n', generate, texture and draw the a plane of width = n…
iansmathew
  • 367
  • 1
  • 3
  • 13
0
votes
0 answers

OpenGL es how to generate mesh from array vertices

I have an array of some xyz vertices that I am wanting to have rendered to form faces for a 3d shape. This array will eventually be based on input data, but for now I am using an example array. Currently I am drawing the shape by indexing three…
0
votes
0 answers

Poor openGL performance with triangle strips

My program is a 3D Spectrum processor which will show signal strength(y) vs frequency(x) vs time (z). It essentially plots a 3d height map, the height of the vertices corresponding to signal strength. The basic program flow is to create a height…
Tom
  • 527
  • 1
  • 8
  • 28
0
votes
1 answer

Triangle Primitives Canvas

Is there a possibility to draw on the canvas of HTML page the gradient primitives? An example of what I want (I did it in another programming language): (excuse me for my English, if I do not write correctly)
Nick Latkovich
  • 115
  • 1
  • 7
0
votes
1 answer

Triangulating a Plane in WebGL

I'm trying to construct a plane out of triangles in WebGL. My code for the constructor looks like this: function plane( points_transform ) { shape.call(this); // Inherit class shape’s array members by calling parent constructor if(…
cheng
  • 1,264
  • 2
  • 18
  • 41
0
votes
0 answers

Looking underneath a GL_TRIANGLE_STRIP

I'm trying to fill and outline the shape below. I do this with a combination of GL_LINES and GL_TRIANGLE_STRIP. Everything looks fine from the top-side. However, when tilting the model to see underneath, the filled triangle strip does not follow the…
Alchete
  • 1,629
  • 2
  • 18
  • 29
0
votes
0 answers

Working out heightmap normals in DirectX using triangle strips

I'm trying to load in heightmap data but I'm struggling to figure out how to work out the normals. Have looked online but can't seem to find anything useful. I store the vertices using m_HeightMapVtxCount = (m_HeightMapLength - 1) * m_HeightMapWidth…
Chris
  • 49
  • 4
0
votes
0 answers

Given this parabola equation with GL_LINE_STRIP, I need parabola shaped cylinder with GL_TRIANGLE_STRIP?

I have code that draws a parabola given two end points and a value for droop/sag to simulate a wire. I'm currently using a GL_LINE_STRIP to draw it, but it's limited to pixel thicknesses, and I need world coordinate thickness. So what I need to do…
Robbie P.
  • 151
  • 1
  • 11
0
votes
2 answers

Issues with making an OpenGL plane out of triangles

I am trying to make a plane using OpenGL, to some extent the code works but I get weird results on some indices. I will try to explain my code the best I can, it's a mixture of my code and what I have found online. The MAIN: All the set-up happens…
user1031204
  • 701
  • 1
  • 8
  • 30
0
votes
1 answer

Drawing normal faces with triangle strips?

I am having to calculate the normals for a triangle strip and am having a issue where every other triangle is dark and not shaded well. I am using the flat shade model. I can't tell if it has to do with the winding direction. When I look under the…