Setting ZBuffer

i have big problem to find pixelformat where depth buffer works correctly.

my code is:


m_pfd.nSize			= sizeof(m_pfd);
m_pfd.nVersion		= 1;
m_pfd.iPixelType	= PFD_TYPE_RGBA;
m_pfd.cColorBits	= 32;
m_pfd.cDepthBits	= 32;
m_pfd.cStencilBits	= 8;
m_pfd.iLayerType	= PFD_MAIN_PLANE;

// Get the pixelformat of this setup.
int						pf;

if (!(pf = ::ChoosePixelFormat(m_hDC,&m_pfd)))
    GiottoPrintf(GIOTTO_MSG_INITIALIZATION,"ChoosePixelFormat() failed!");
    return false;

// Get a description of the pixelformat chosen
if (!(DescribePixelFormat(m_hDC,pf,sizeof(PIXELFORMATDESCRIPTOR),&pfdCheck)))
    GiottoPrintf(GIOTTO_MSG_INITIALIZATION,"GLView: ChoosePixelFormat() The OpenGL Pixeldescription couldn't be retrieved!");
	return false;

// Is hardware accelerated ?
if (((pfdCheck.dwFlags & PFD_GENERIC_ACCELERATED) == 0) && ((pfdCheck.dwFlags & PFD_GENERIC_FORMAT) > 0))
	GiottoPrintf(GIOTTO_MSG_INITIALIZATION,"The OpenGL driver that's currently active doesn't support hardware acceleration or there is no decent OpenGL driver installed.");

if (SetPixelFormat(m_hDC,pf,&pfdCheck)!=TRUE) 
    GiottoPrintf(GIOTTO_MSG_INITIALIZATION,"SetPixelFormat() failed!");
    return false;

if ((m_hRC = wglCreateContext(m_hDC)) == NULL) 
    GiottoPrintf(GIOTTO_MSG_INITIALIZATION,"Cannot create rendering context");
	return false;

if (!wglMakeCurrent(m_hDC,m_hRC)) 
	GiottoPrintf(GIOTTO_MSG_INITIALIZATION,"wglMakeCurrent() failed");;
	return false;

but in windowed mode with G400 depth buffers doesn’t work…anyone knows why???

Originally posted by Powerino:
[b]i have big problem to find pixelformat where depth buffer works correctly.

m_pfd.cColorBits = 32;
m_pfd.cDepthBits = 32;

The pfd entry cColorBits for RGBA buffers is excluding alpha. You should specify 24.

Are you sure that the G400 supports a 32bit depth buffer? Few consumer level cards do(if any). See other thread in here regarding just that.

Yes G400 works with 32 bit depth buffer!!!

i have the same problem with gforce4mx!!!

with Color depth 32, Depth 32 stencil 0


Found this article which might interest you. According to it, 32bit z-buffer support isn’t enabled in GL drivers. This was however, 4 YEARS ago. Maybe Matrox has fixed it and there is some another problem, or maybe not. Matrox isn’t really famous for their awesome GL support. Maybe you can whip up a simple Direct3D app and see if it works under DX(they claim it does). And I’m assuming you’re using the latest drivers.

Thanks very much…i have tried all pixelformat and i have found that all pixelformat with doublebuffer in windowed mode doesn’t work with my engine…
disabling doublebuffer it works fine!!!
WHY if the DescribePixelFormat tells me there a a valid pfmt with depth buffer after in opengl it doesn’t work!!!

Any idea how to find a valid pixelformat for my application…using old opengl driver i can’t use new wglARB functions for pixelformat!!!

Originally posted by Mazy:
I dont really think you have 32bit zbuffer on g400.

I highly doubted this too, so I checked the specs at Matrox. And in fact, they do say they support a 32bit depth buffer, including an 8bit stencil.

I also looked for something like “32bit depth only supported if: …” but couldn’t find any.

you have 2 choices
either try to send different configs in pfd and try choosepixelformat until you get a good result ( in windows you often have the limitation that if the desktop is 16bit the opengl must be 16bit, and the zbuffer cannot exceed the color in bits. )

or number 2, loop through all pixelformats and run describepixelformats on them and make your own search between the formats.

You’re requesting a stencil buffer. You can’t get more than a 24 bit z buffer then.
I don’t know whether 32bit z only is possible.