Polygon Counter

Hi all,
I am using my own implementation of frustum culling. I wanna know if it is possible to query opengl to get number of polygons drawn in my scene.

Before someone sends you to beginners forum…

You can’t get the number of the triangles on the fly, but you can use the selection mode to get it.

Goes like tnis:

  1. glSelectBuffer(size, buffer);
  2. glRenderMode(GL_SELECT);
  3. Draw your scene
  4. numberOfTris = glRenderMode(GL_RENDER);

Please note, that you must have a selection buffer allocated, and it must be big enough to hold all possible triangles drawn (meaning size=3*maximum number of triangles), or else the second glRenderMode call will return -1. Actually, the buffer should be even a little larger, since clipping can create additional triangles.

-Ilkka

My god, that’s a reasonable use of GL selection!

Note that I haven’t ran into a consumer level graphics card that hardware accelerates selection. So use sparingly. Setup a key or a command to toggle it on and off.

Heh, ya.
I would suggest counting them yourself instead. Shouldn’t be too hard.

It is easy to count on your own. Just add up your glVertex calls and the count you submit to glDrawElements. But you don’t know how many vertices get culled.