lacas
lacas

Reputation: 14066

OpenGL-ES TRIANGLE_STRIP error

    float coords[] = {
              -1.0f,  1.0f, 0.0f,  // 0, Top Left
              -1.0f, -1.0f, 0.0f,  // 1, Bottom Left
               1.0f, -1.0f, 0.0f,  // 2, Bottom Right
               1.0f,  1.0f, 0.0f,  // 3, Top Right
    };


    float texCoords[] = { 
            0.0f, 0.0f, 
            0.0f, 1.0f, 
            1.0f, 1.0f, 
            1.0f, 0.0f, 
        };

on draw:

gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, coords.length/dimension);

draw normally, but

gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, coords.length/dimension);

this only draw the half square, why?

Upvotes: 0

Views: 1705

Answers (1)

detunized
detunized

Reputation: 15289

For this to work the order of the points should be: TL, BL, TR, BR.

When you specify a fan, the points go around the very first point. Each triangle is composed from that very first point, the next point on the list and the last point from the previous triangle.

With the strip it's different. Strip triangles are using last two points from the previous triangle and the new one on the list. This has a side effect: every triangle has the opposite winding (CW than CCW, then CW again and so on).

enter image description here

Upvotes: 3

Related Questions