Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 thestien   Members   -  Reputation: 102

Like
0Likes
Like

Posted 26 March 2012 - 03:33 PM

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 :)

Sponsor:

#2 Postie   Members   -  Reputation: 1118

Like
0Likes
Like

Posted 26 March 2012 - 08:36 PM

Enabling the z-buffer isn't enough, you also need to enable z-buffer writes.
Currently working on an open world survival RPG - For info check out my Development blog: ByteWrangler

#3 thestien   Members   -  Reputation: 102

Like
0Likes
Like

Posted 26 March 2012 - 11:02 PM

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 :)

#4 thestien   Members   -  Reputation: 102

Like
0Likes
Like

Posted 27 March 2012 - 01:00 AM

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;






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS