Question

I want to draw many spheres (~100k) using OpenGL. So far, I'm doing something like

for (int i=0; i<pnum; i++){
     glPushMatrix();
     glTranslatef(bpos[i].x, bpos[i].y, bpos[i].z);
     glCallList(DListSPHERE);
     glPopMatrix();
}

Before using proper spheres, I used GL_POINTS. That allowed me to call glDrawArrays with an array containing all points which was very efficient. Is there a better way than the above code to draw many, identical objects?

Was it helpful?

Solution

Have a look at this page on instancing: it contains many references:

See also Geometry instancing on Wikipedia.

OTHER TIPS

If you draw ~100k spheres, you might want to consider raycasting them instead of using polygon meshes to approximate them. The papers GPU-Based Ray-Casting of Quadratic Surfaces by Sigg et al. (2006) and Splatting Illuminated Ellipsoids with Depth Correction by Gumhold (2003) show how to do this. If you do this, you can reuse much of your fast point sprite code.

You could use point sprites and a fragment shader to duplicate the effect of a rendered sphere without the actual sphere geometry. I would try instancing first, however.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top