Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing many spheres in OpenGL

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?

like image 694
hanno Avatar asked Jan 03 '10 15:01

hanno


1 Answers

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

  • Some test made that shows when to use instancing and when not: http://www.ozone3d.net/blogs/lab/?p=87

  • An OpenGL implementation of a pseduo-instancing (recommended for old hardware). glsl_pseudo_instancing.pdf

  • OpenGL instancing: http://www.opengl.org/registry/specs/EXT/draw_instanced.txt

See also Geometry instancing on Wikipedia.

like image 102
Gregory Pakosz Avatar answered Sep 22 '22 06:09

Gregory Pakosz