OpenGL: The fastest way to draw a mixture of triangles and ATVs?

I have a grid data structure with polygons, which can be either triangles or squares. What is the fastest way to do this using OpenGL?

The slowest way is to iterate over the structure and for each polygon to do the corresponding glBegin() .. glEnd()with GL_QUADSor GL_TRIANGLES. I would like to avoid glBegin() .. glEnd()for each and every polygon.

Another option is to divide the structure into two structures: one containing triangles, and one containing squares, and then go through them separately. This is also something that I would like to avoid, since I really want to keep them all in one structure.

Unfortunately, triangulating quadrants into triangles is currently not an option.

Is there a good solution for this?

+3
source share
3 answers

You might want to create two index tables, one for the squares for the triangles, and then write all the squares, and then the triangles (or the inverse). To draw using an array of indices, use glDrawElements with a set of glVertexPointer and glEnableClientState to make it work.

, , VBO . , GPU.

+3

.

:

glBegin(GL_TRIANGLES);
for each (object *a in objectList)
  if (a->type == TRIANGLE)
    glVertex3fv(a->vertices);
  if (a->type == QUAD)
  {
    glVertex3f(a->vertices[0]);
    glVertex3f(a->vertices[1]);
    glVertex3f(a->vertices[2]);

    glVertex3f(a->vertices[2]);
    glVertex3f(a->vertices[1]);
    glVertex3f(a->vertices[3]);
  }
glEnd();

, ( ), !

+3

glPolygonMode (GL_LINE) GL_QUADS, glEdgeFlagPointer() , . GL_TRUE , GL_FALSE .

glEnableClientState (GL_EDGE_FLAG_ARRAY).

+1

Source: https://habr.com/ru/post/1710233/


All Articles