3d objects in the distance being draw in the front of closer objects

Started by
2 comments, last by thestien 12 years, 1 month ago
Hi guys, i have been following an example code in a book and have now finished the book and the last example is a mock solor system.

The code is Frame based the frames are Scene, Sun, Planets, Earth and Moon.

The Scene is the parent of sun which is the parent of the Planets and Earth and earth is the parent of Moon.

now all of the objects rotate around each other in the expected way and when they pass behind the Sun they are drawn behind it. the problem occurs when they pass infront of the sun. The sun is still drawn infront evan though it is smaller and further away from my view.

i dont really want to post the code as there are many lines and im not sure which parts will be relavent so could you advise me as to why this is happening? i have enabled the z buffer but i think i may not have done it correctly?

i will post any code or all of it if you think it would be easier to help me.

the Frames have objects added to them all of which are derived from a base class which has a function Render() so when i come to render them all i call the Scene's Render function which goes through the list of Frames and Objects and calls all of thier Render functions. could it be the order that they are called? or should the z buffer sort this out for me?

well thanks for your help in advance :)
Advertisement
Enabling the z-buffer isn't enough, you also need to enable z-buffer writes.
[size="2"]Currently working on an open world survival RPG - For info check out my Development blog:[size="2"] ByteWrangler
ah ok cool sorry im still a noob atm how do i enable the writes? and where should i enable it every frame? or just in my main init function?

thanks for the reply :)
Sorry guys i have managed to solve this one and it seems to of been a mistake made by me when trying to fix the code before i had set the viewport max to 2.0f...
but now it acts as it should. incase any one in the future does a similar thing.

typedef struct D3DVIEWPORT9 {
DWORD X;
DWORD Y;
DWORD Width;
DWORD Height;
float MinZ;
float MaxZ; // set to 1.0f if you get the problem i had
} D3DVIEWPORT9, *LPD3DVIEWPORT9;

This topic is closed to new replies.

Advertisement