Direct3D ZBuffer
I can not seem to get a ZBuffer working in my program. I set it up like so:
DDPIXELFORMAT ddpfZBuffer;
g_pD3D->EnumZBufferFormats( IID_IDirect3DHALDevice,
EnumZBufferCallback, (VOID*)&ddpfZBuffer );
if( sizeof(DDPIXELFORMAT) != ddpfZBuffer.dwSize )
{
REGISTER_FAILURE("ZBuffer sizes dont match!");
return FALSE;
}
ddsd.dwFlags = DDSD_CAPS/DDSD_WIDTH/DDSD_HEIGHT/DDSD_PIXELFORMAT;
ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER / DDSCAPS_3DDEVICE;
ddsd.dwWidth = Width;
ddsd.dwHeight = Height;
memcpy( &ddsd.ddpfPixelFormat, &ddpfZBuffer, sizeof(DDPIXELFORMAT) );
ddsd.ddsCaps.dwCaps /= DDSCAPS_VIDEOMEMORY;
hr = g_pDD->CreateSurface( &ddsd, &g_pDDSZBuffer, NULL );
if(FAILED(hr))
{
REGISTER_FAILURE("Could not create ZBuffer surface!");
return hr;
}
// Attach the z-buffer to the back buffer.
hr = g_pDDSBack->AddAttachedSurface( g_pDDSZBuffer );
if(FAILED(hr))
{
REGISTER_FAILURE("Could not attach surface!");
return hr;
}
The EnumZBufferCallback function is like so:
static HRESULT WINAPI EnumZBufferCallback( DDPIXELFORMAT* pddpf,
VOID* pddpfDesired )
{
if( pddpf->dwFlags == DDPF_ZBUFFER )
{
memcpy( pddpfDesired, pddpf, sizeof(DDPIXELFORMAT) );
// Return with D3DENUMRET_CANCEL to end the search.
return D3DENUMRET_CANCEL;
}
return D3DENUMRET_OK;
}
And after creating the Device, I call:
g_pd3dDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
g_pd3dDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);
g_pd3dDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE);
Without this code, I can get a spinning triangle on a blue background, when I put this code in, I get the blue background, but the triangle wont draw.Is there some initialization im missing?
None of the functions return an error, and since the viewport will clear, im thinking its not a major problem in my setup.
I also add the D3DCLEAR_ZBUFFER to my Clear commands.
Edited by - Shaw Mishrak on 7/6/00 8:20:06 PM
Do you clear your zbuffer to 1.0f or 0.0f?
I clear to 1.0, and there is no need to change any zbuffering states... (not unless I want to do some neat tricks... )
I clear to 1.0, and there is no need to change any zbuffering states... (not unless I want to do some neat tricks... )
One thing you do wrong is that you create the surface with the DDSCAPS_3DDEVICE flag present. Remove it and see what happens.
One more thing you should know is that you can''t always put the z buffer in video memory. If you have a software device you have to put it in system memory.
One more thing you should know is that you can''t always put the z buffer in video memory. If you have a software device you have to put it in system memory.
Thanks for the help. Its solved now. Right now, im running in Hardware-Acceleration mode only and I check for possible error messages for that wasn't the problem.
Thanks,
Shaw Mishrak
Edited by - Shaw Mishrak on July 7, 2000 2:24:19 PM
Thanks,
Shaw Mishrak
Edited by - Shaw Mishrak on July 7, 2000 2:24:19 PM
I just thought you should now that if you wan''t a program to work on a computer without hardware acceleration.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement