# Voxels in OpenGL?

2 replies to this topic

### #1Rei

New Member

• Members
• 1 posts

Posted 04 March 2004 - 03:03 AM

I'm working on a voxel-based 3d engine in OpenGL. I've done voxel engines before in which the graphics library's only job was to blit pixels to the screen - my code did all the 3d math and primitive rendering. However, in the interests of efficiency, I'd like to use OpenGL this time to take advantage of fast routines and hardware acceleration. The problem is, OpenGL doesn't seem to be very aware of concepts related to voxel engines.

For example, regardless of the type of voxel engine (surface rendering, depth rendering, etc), you generally need a method to blit a 2d shape in 3d space. Technologically, this is very simple. Once the points are rotated into the display space, for each point you get the z value, and draw your 2d primitive (generally a square, rectangle, or circle) into the z buffer with all points having the same z depth. Easy - easier than your average polygon draw routine, in fact. However, for the life of me, I can't think of an efficient way to do that in OpenGL. The only ways I can think of are:

A) Replace each voxel with four 3d coordinates that act as corners to a polygon. Not only do I beforehand have to calculate the proper location of these points to center this polygon around the voxel, but OpenGL has to do 4 times the work of rotating and then has to then do a polygon draw routine in 3d. That'll probably run *slower* than just writing my own routines and going without hardware acceleration.

For however much space the voxel would take up on the screen, you blit 3d points using OpenGL. Of course, if your voxel is up close and is taking up 20 by 20 pixels, you're going to need 400 3d points drawn with OpenGL, and the rotating of those points is going to be unbearable. Additionally, you still need to calculate where all those points are.

Both of these options are, quite clearly, unfeasable. Does anyone have any better ideas, or is a voxel-engine writer stuck with writing their own entire unaccelerated rotation and primitive functions for no good reason other than OpenGL doesn't contain a very simple "draw a 2d shape in 3d" function?

Ideas?

### #2anubis

Senior Member

• Members
• 2225 posts

Posted 04 March 2004 - 03:41 AM

you could use point sprites. they are usually used to render particle systems. instead of 4 points you only specifiy one and opengl does the rest for you (rendering a billboarded quad that is). i'm not sure if i'm getting you here because i never worked with voxels and know little about it (just the basic theory...). if drawing a square is all you need to do this might be what you want
If Prolog is the answer, what is the question ?

### #3soundeye

New Member

• Members
• 1 posts

Posted 07 March 2004 - 01:35 AM

hey there couldn't resist
might wan't to take a look at
http://www.vis.uni-s...pre-integrated/

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users