Jump to content
  • Advertisement
Sign in to follow this  
The_Nerd

OpenGL Problem with the depth buffer

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I've had this problem before, and it took me many hours to track it down. This time I am just going to ask you guys and hopefully get and explaination, since I forgot what I did to make it stop. Look at this picture: See all the nastyness? When I initialize OpenGL I set the frustum as follows: glMatrixMode (GL_PROJECTION); glFrustum (-1.0, 1.0, 1.0, -1.0, 1.0, 4000.0); glScalef (1.0, 1.0, 1.0); glMatrixMode (GL_MODELVIEW); glDepthFunc(GL_LEQUAL); When I draw my 3D stuff I set perspective as follows: glMatrixMode (GL_PROJECTION); glLoadIdentity(); gluPerspective(90, tpEg->Screen.fAspect, 0, 1); glMatrixMode (GL_MODELVIEW); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity (); Draw3D(); And when I draw my 2D stuff: glMatrixMode (GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-100, 100, 100, -100); glMatrixMode (GL_MODELVIEW); Draw2D(); Whats causing the depth buffer to act so screwed up?

Share this post


Link to post
Share on other sites
Advertisement
Yes depth testing is enabled right before my glBegin in Draw3D();
glEnable(GL_DEPTH_TEST);

[Edited by - The_Nerd on September 16, 2004 11:00:46 PM]

Share this post


Link to post
Share on other sites
There's a call to gluPerspective() that's messing things up (sets the near plane to 0):

gluPerspective(90, tpEg->Screen.fAspect, 0, 1);

should probably be

gluPerspective(90, tpEg->Screen.fAspect, 1.f, 4000.f);

Share this post


Link to post
Share on other sites
Yup, deffinately can't set the near plane to 0.

Furthermore, you set your camera frustum when you initialize opengl (glFrustum), but then you destroy it when you draw 3D, since you load identity.

You're going to want to do something for your frustum after gluPerspective (such as gluLookAt).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!