Sign in to follow this  
slowmike

distant object renders over near object

Recommended Posts

slowmike    144
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.

Share this post


Link to post
Share on other sites
Gage64    1235
Quote:
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?


Only if you're using the depth buffer. Can you post your code?

Share this post


Link to post
Share on other sites
shwasasin    482
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 );

Share this post


Link to post
Share on other sites
GamerSg    378
Are you by any chance clearing the depth buffer between drawing the 2 objects? I cant think of any other reason besides your depth buffering not being enabled.

Share this post


Link to post
Share on other sites
Gage64    1235
Setting a render state is not enough, you also need to set the appropriate parameters in D3DPRESENT_PARAMETERS. The Debug Runtimes can often point out such errors.

If this doesn't fix it, we'll need to see the code (in source tags. See the FAQ if you don't know what that means).

Share this post


Link to post
Share on other sites
slowmike    144

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.

Share this post


Link to post
Share on other sites
Gage64    1235
Quote:
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."


That's only for Visual C# users.

Also, don't forget to clear the depth buffer.

Share this post


Link to post
Share on other sites
slowmike    144
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.

Share this post


Link to post
Share on other sites
slowmike    144
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this