Question

I want to parse a model and render 4-vertex polygons (rectangles) in OpenGL ES 2.0, and instead of using two triangles I thought of using one triangle strip for each quad/rectangle.

The problem is my rectangles are not connected throughout the model. If I have three quads (12 vertices) I would like to draw them like this (numOfQuadFaces = 3):

glDrawArrays(GL_TRIANGLE_STRIP, 0, numOfQuadFaces*4);

With the vertex array ordered so that the a new quad is begun every four vertex. But of course OpenGL interprets it like a new triangle is begun for every new vertex beyond the third vertex in the array. Can I specify somewhere that I want individual triangle strips/quads of length 4? - So that I draw similar to this (if course in only on glDrawArrays- call):

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 4, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 8, 4);
Était-ce utile?

La solution

Your best option is to convert the quads to triangles. In ordinary OpenGL if you used indexed triangle strip, there is glPrimitiveRestartIndex which basically specifies an index that when sent restarts the strip, this isn't available in OpenGL ES 2.0 though so I guess that's no help.

Another option is to connect the "strips" with degenerate triangles, but this will take as much memory as just converting the quads to triangles (two extra vertices).

Autres conseils

you can render degenerate triangles, by inserting extra points, resulting in line shaped triangles, the graphics drivers will optimize these out and render disconnected triangle strips, which can be quad shaped (two triangles)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top