Archived

This topic is now archived and is closed to further replies.

CoreWill

Z-Buffer Problem

Recommended Posts

I have studied Quake3 BSP Loader1 on www.gametutorials.com and i convert it to Direct3D, but i got a problem with Z-buffer. The faces' order is wrong, if i rendered them from front to back. i'm sure i have enabled z-buffer. see screen below: [edited by - corewill on October 7, 2003 2:37:23 AM]

Share this post


Link to post
Share on other sites
dunno.

Have you checked your far, near plane settings.

Once, I was wondering for ages why Z-buffer wasn''t working and in the end it turned out my far plane was set to 0. Dumb!
Because it was dumb it took me so long ot find it.

Share this post


Link to post
Share on other sites
My frustum-view setting is here:

D3DXMATRIX matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 3.0f, 100000.0f );
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );

so, near plane is 3 ,and far plane is 100000

[edited by - corewill on October 6, 2003 8:26:15 AM]

Share this post


Link to post
Share on other sites
That looks more like a culling order or incorrect texture coordinate problem than anything to do with the Z buffer to me.

Try setting D3DRS_CULLMODE to D3DCULL_CW (most OpenGL apps use reverse winding due to using different handedness). Also make sure the texture coordinates are correct and any processing or flags that are being applied are doing what you''d expect.

Another possibility might be incorrect use or driver interpretation of ZBIAS/DEPTHBIAS states.

For the Z buffer, try it with 32bit and take a 0 off the far plane value - if that fixes it, then it is the Z buffer - if not, it''s likely to be something else.

--
Simon O''Connor
3D Game Programmer &
Microsoft DirectX MVP

Share this post


Link to post
Share on other sites
1).I do think D3DRS_CULLMODE should set to D3DCULL_CCW,because if it is D3DCULL_CW, everything is wrong( if i'm in the room ,i can't see anything, only when i'm out of the room ,i can see the walls )
2).I'm sure that the texture coordinate is right.
3).I dont know the ZBIAS , can you explain it in detail. how to use it?

Here is my DX INI Code, IS IT RIGHT???

void InitFullScreen(int width,int height,D3DPRESENT_PARAMETERS *d3dpp)
{
d3dpp->Windowed=FALSE;
d3dpp->BackBufferCount=1;
d3dpp->BackBufferFormat=D3DFMT_R5G6B5;
d3dpp->BackBufferWidth=SCREEN_WIDTH;
d3dpp->BackBufferHeight=SCREEN_HEIGHT;
d3dpp->hDeviceWindow=g_hWnd;
d3dpp->SwapEffect=D3DSWAPEFFECT_DISCARD;
d3dpp->PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
}

void InitWindow(int with,int height,D3DPRESENT_PARAMETERS *d3dpp)
{
d3dpp->Windowed = TRUE;
d3dpp->hDeviceWindow=g_hWnd;
d3dpp->SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp->BackBufferFormat = D3DFMT_UNKNOWN;
}

bool InitDX(HWND hwnd,int width,int height,bool bFullScreen)
{
if(NULL==(g_pD3D=Direct3DCreate9(D3D_SDK_VERSION)))
{
MessageBox(hwnd,"Failed create direct3d9",NULL,NULL);
return false;
}

D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));

if(bFullScreen)
{
InitFullScreen(width,height,&d3dpp);

if(FAILED(g_pD3D->CreateDevice( D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL, hwnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice )) )
{
MessageBox(hwnd,"Failed in create device!",NULL,NULL);
return false;
}
}
else
{
InitWindow(width,height,&d3dpp);

if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL, hwnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice )) )
{
MessageBox(hwnd,"Failed in create device!",NULL,NULL);
return false;
}
}

g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
g_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, D3DZB_TRUE);
g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE);
g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
g_pd3dDevice->SetSamplerState (0, D3DSAMP_MAGFILTER,3 );
g_pd3dDevice->SetSamplerState (0, D3DSAMP_MINFILTER,3 );

return true;
}

if i enabled d3dpp->EnableAutoDepthStencil,and set d3dpp->AutoDepthStencilFormat as D3DFMT_D24X8, or D3DFMT_D24S8, D3DFMT_D16, i can see nothing. i'm sure my display card support D3DFMT_D16.

[edited by - corewill on October 7, 2003 2:22:50 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by S1CA
Another possibility might be incorrect use or driver interpretation of ZBIAS/DEPTHBIAS states.

For the Z buffer, try it with 32bit and take a 0 off the far plane value - if that fixes it, then it is the Z buffer - if not, it''s likely to be something else.



I set D3DRS_DEPTHBIAS as 1 or 0, it''s both wrong all the same .
if i set AutoDepthStencilFormat as D3DFMT_D32, it will fail to create D3D device.

Share this post


Link to post
Share on other sites
quote:

d3dpp->EnableAutoDepthStencil,and set d3dpp->AutoDepthStencilFormat



In your above code you dont set these. Do you set them anywhere?

Neil

WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!

Share this post


Link to post
Share on other sites