Jump to content
  • Advertisement

Archived

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

Jaeden

ZFighting / Depth Writing problem...

This topic is 5281 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, guys... I''m having a time crunch crisis with this D3D system and was wondering you you could lend a hand. When I draw any type of mesh, even the ones D3DXCreate... make, they seem to draw inside out, but only partially. The lighting is all screwed up on them, and I can see right through them. I also can move behind objects, and my character is still drawn. Obviously, my money is on a ZFighting/depth test problem, but I can''t find the solution. Pasted please find my D3D init code and my clear function. If there is anything else you need, please let me know. Thanks for your help. /////////////////////// // init /////////////////////// BOOL Direct3D::Initialize(HWND hWnd, DWORD dwWidth, DWORD dwHeight, BOOL bWindowed, int nBackBuffers, bool Alpha16) { // Store parameters iWinSizeX = dwWidth; iWinSizeY = dwHeight; // Initialize object IDirect3D9 *pD3DObj = Direct3DCreate9(D3D_SDK_VERSION); if (!pD3DObj) return FALSE; //Get the display modes of the device if(FAILED(pD3DObj->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3dDisplay))) return FALSE; // Get the capabilities of the hardware. D3DCAPS9 d3dCaps; if(FAILED(pD3DObj->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps))) return FALSE; // Test which is supported, hardware or software vertex processing. DWORD dwVertProc = 0; if(d3dCaps.VertexProcessingCaps) dwVertProc |= D3DCREATE_HARDWARE_VERTEXPROCESSING; else dwVertProc |= D3DCREATE_SOFTWARE_VERTEXPROCESSING; //D3DCREATE_MIXED_VERTEXPROCESSING // Init structure... ZERO(tD3DSettings) // Wipe it out (in case of re-init) tD3DSettings.BackBufferHeight = (bWindowed) ? dwHeight : d3dDisplay.Height; tD3DSettings.BackBufferWidth = (bWindowed) ? dwWidth : d3dDisplay.Width; tD3DSettings.BackBufferFormat = d3dDisplay.Format; tD3DSettings.BackBufferCount = nBackBuffers; tD3DSettings.hDeviceWindow = hWnd; tD3DSettings.Windowed = bWindowed; tD3DSettings.SwapEffect = D3DSWAPEFFECT_DISCARD; tD3DSettings.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER; tD3DSettings.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; tD3DSettings.EnableAutoDepthStencil = TRUE; tD3DSettings.AutoDepthStencilFormat = D3DFMT_D24S8; // Store the aspect ratio fAspectRatio = float(tD3DSettings.BackBufferWidth) / tD3DSettings.BackBufferHeight; // Use the structure to create the device pointer. if (FAILED(pD3DObj->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, dwVertProc, &tD3DSettings, &pDevice))) return FALSE; // Initialize back buffer pointer.. We need this to switch back after screenshots pDevice->GetRenderTarget(0, &pBackBufferSurface); // Create the texture and surface we are going to use to handle screenshots. pDevice->CreateTexture(tD3DSettings.BackBufferWidth, tD3DSettings.BackBufferHeight,1,D3DUSAGE_RENDERTARGET,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&pScreenshotTexture,NULL); pScreenshotTexture->GetSurfaceLevel(0, &pScreenshotSurface); // Initialize sprite if (FAILED(D3DXCreateSprite(pDevice, &pD3DSprite))) return FALSE; // Initialize matrix stack if (FAILED(D3DXCreateMatrixStack(NULL, (LPD3DXMATRIXSTACK*)&pMatrixStack))) return FALSE; pMatrixStack->LoadIdentity(); return TRUE; } /////////////////////// // clear /////////////////////// static void Direct3D::Clear(int nColorR = 0, int nColorG = 0, int nColorB = 0, float fDistance = 1.0f, int nStencilBuffer = 0) { DWORD dwFlag = D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER; dwFlag |= (nStencilBuffer) ? D3DCLEAR_STENCIL : 0; pDevice->Clear(NULL, NULL, dwFlag, D3DCOLOR_XRGB(nColorR, nColorG, nColorB), fDistance, nStencilBuffer); }

Share this post


Link to post
Share on other sites
Advertisement
It might be a culling problem. Turn off culling and see if it works. Also, check the value of your near plane in your projection matrix. Make sure it''s not too close to 0.0.

neneboricua

Share this post


Link to post
Share on other sites
did u enable zbuffering? culling?
did u set the projection matrix with a non-zero minz?
are u using the right FVF?
is lighting or specular enabled?
are u setting wrong blending states?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!