Public Group

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

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

Recommended Posts

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?

Share on other sites
Enabling the z-buffer isn't enough, you also need to enable z-buffer writes.

Share on other sites
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?

Share on other sites
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; 

• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 24
• 43
• 75