Cube using one GL_TRIANGLE_STRIP

Is it possible to draw an entire cube using only one GL_TRIANGLE_STRIP ?

Obviously, this is only the cube combinator that bothers me here, it can also be stretched to any kind of box or similar object.

+8
opengl gl-triangle-strip
source share
3 answers

From the article Optimizing Triangle Stripes for Quick Rendering of Evans, LΓΆsen, and Warsaw:

triangle strip chart

+10
source share

Yes, after several experiments, I myself found the answer. Imagine that the corners of your cube are colored alternating black and white. Draw the edge of the triangle along each face between the two black corners. Thus, the diagonals form a tetrahedron inside the cube. For the cube [0,1] Β³, the possible sequence of coordinates will be as follows:

 Vertex Triangle Face ------+-----------+----- 0 0 0 0 1 0 1 0 0 000 010 100 **0 1 1 0 100 010 110 **0 1 1 1 100 110 111 1** 0 1 0 111 110 010 *1* 0 1 1 111 010 011 *1* 0 0 1 011 010 001 0** 1 1 1 011 001 111 **1 1 0 1 111 001 101 **1 1 0 0 111 101 100 1** 0 0 1 100 101 001 *0* 0 0 0 100 001 000 *0* 0 1 0 000 001 010 0** 
+3
source share

For those of you who are lazy (like me), here you can copy the rob mayoff version of answer;)

 static const GLfloat cube_strip[] = { -1.f, 1.f, 1.f, // Front-top-left 1.f, 1.f, 1.f, // Front-top-right -1.f, -1.f, 1.f, // Front-bottom-left 1.f, -1.f, 1.f, // Front-bottom-right 1.f, -1.f, -1.f, // Back-bottom-right 1.f, 1.f, 1.f, // Front-top-right 1.f, 1.f, -1.f, // Back-top-right -1.f, 1.f, 1.f, // Front-top-left -1.f, 1.f, -1.f, // Back-top-left -1.f, -1.f, 1.f, // Front-bottom-left -1.f, -1.f, -1.f, // Back-bottom-left 1.f, -1.f, -1.f, // Back-bottom-right -1.f, 1.f, -1.f, // Back-top-left 1.f, 1.f, -1.f // Back-top-right }; 
+1
source share

All Articles