Skip to main content
GameDev.net gamedev.net
🔒 Locked

distant object renders over near object

Started by slowmike Apr 24, 2008 at 12:05 PM 9 replies 2.2k views
Original Post
slowmike
slowmike
I've got an object located at about 10.0f on the Z axis and another object at about 1.0f on the Z axis. For some reason, the object that's farther away is being rendered in front of the closer object. Any thoughts? When I move my camera (point of view), I can see that both objects are located at their correct 3D positions. But no matter which side of the world I'm looking in from (front or back), the same object is always displayed in front of the other. I'm thinking it has something to do with my World, View, or Projection matrix. Or maybe it's a render_state problem. I know that I'm rendering the object that's always displayed in front last, but this isn't 2D, so it shouldn't matter the order in which the objects are being rendered. Correct? Thanks.
shwasasin
shwasasin
Sounds like you need to enable z-buffering support. Something along the lines below would do it.

In OpenGL:
glEnable(GL_DEPTHTEST);

In Direct3D:
pDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
slowmike
slowmike
I'm setting the render state, D3DRS_ZENABLE to true. (??)

Any code snippet in particular that you'd like to see?
slowmike
slowmike
D3DPRESENT_PARAMETERS d3dpp;ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));if(fullscreen){	d3dpp.Windowed = false;	d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP;	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;	d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;}else{	d3dpp.Windowed = true;	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;}d3dpp.BackBufferFormat = d3ddm.Format;d3dpp.BackBufferCount = 1;d3dpp.BackBufferWidth = winWidth;d3dpp.BackBufferHeight = winHeight;d3dpp.hDeviceWindow = hwnd;d3dpp.EnableAutoDepthStencil = true;d3dpp.AutoDepthStencilFormat = D3DFMT_D16;if(FAILED(d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,		D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &d3dDevice)))		return false;


For the debug runtimes.. I selected "Use Debug" in the control panel, but I couldn't find where to complete this step: "Under Managed Projects, you need to select "Enable unmanaged debugging" in the Debug section of the project properties."

I'm going to trace back some pointers to see if I've got some garbage data that's not triggering an error. Thanks for the help.
RabidDog
RabidDog
Do you have a zbuffer setup, with write enabled and ztest less than equal?
slowmike
slowmike
Quote:
Also, don't forget to clear the depth buffer.


d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, clearColor, 1.0f, 0);

I make this call once per frame, right before BeginScene. I'm still looking into the problem myself. It's just taking some time, because I'm a bit busy right now.
slowmike
slowmike
I created a new project with the code stripped down to the bare essentials, but the problem remains.

Quote:
Original post by RabidDog
Do you have a zbuffer setup, with write enabled and ztest less than equal?


Can someone please explain which steps this quote is referring to? Thank you.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.