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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With