views:

106

answers:

2

I would like to draw voxels by using opengl but it doesn't seem like it is supported. I made a cube drawing function that had 24 vertices (4 vertices per face) but it drops the frame rate when you draw 2500 cubes. I was hoping there was a better way. Ideally I would just like to send a position, edge size, and color to the graphics card. I'm not sure if I can do this by using GLSL to compile instructions as part of the fragment shader or vertex shader.

I searched google and found out about point sprites and billboard sprites (same thing?). Could those be used as an alternative to drawing a cube quicker? If I use 6, one for each face, it seems like that would be sending much less information to the graphics card and hopefully gain me a better frame rate.

Another thought is maybe I can draw multiple cubes using one drawelements call?

Maybe there is a better method altogether that I don't know about? Any help is appreciated.

+2  A: 

What you're looking for is called instancing. You could take a look at glDrawElementsInstanced and glDrawArraysInstanced for a couple of possibilities. Note that these were only added as core operations relatively recently (OGL 3.1), but have been available as extensions quite a while longer.

nVidia's OpenGL SDK has an example of instanced drawing in OpenGL.

Jerry Coffin
+5  A: 

Drawing voxels with cubes is almost always the wrong way to go (the exceptional case is ray-tracing). What you usually want to do is put the data into a 3D texture and render slices depending on camera position. See this page: http://http.developer.nvidia.com/GPUGems/gpugems_ch39.html and you can find other techniques by searching for "volume rendering gpu".

ybungalobill
Yes, render back to front along the axis that is most aligned with the view direction. Start by rendering quads with transparency. Once that works you can try to insert the "sides" between each layer as well.
phkahler