Game Development Community

Z-buffer ?

by Hadoken · in Torque Game Engine · 01/16/2004 (1:01 pm) · 3 replies

While browsing the source code i saw that a "z-Buffer" is named a few times, so i was wondering if it can be accessed in some simple way like the framebuffer?
This would help a lot in making good special fx.
There is a "depthBits" array which sounds like what i need, but i don't really know how it is used by torque.
Any help on this would be really appreciated.

#1
01/16/2004 (3:57 pm)
Yes - the same way you read from the frame buffer. insetad of using GL_RGB or somesuch, use GL_DEPTH_COMPONENT. Look at the glReadPixels() function.
#2
01/17/2004 (4:15 pm)
Thanks a lot, i'm trying it now.
Do you think that if i do like:
glReadPixels(0, size.y - 1, size.x, size.y, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, (void*)zBufferBmp->getBits(0));
it will be correct? or maybe there is anything wrong with the data types?
#3
01/17/2004 (7:57 pm)
You have to make sure that the bitmap you're copying to is the same size as the area that you're reading. Also, you need to create a bitmap with only 1 channel:

GBitmap* zBufferBmp = new GBitmap(sizex, sizey, BitmapFormat::Alpha);

or somesuch.