Jump to content
  • Advertisement
Sign in to follow this  
chad_420

OpenGL Opengl depth buffer problem

This topic is 4983 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

I have a small program using sdl and opengl, it displays 2 triangles on the screen using the following code... float z = -10.0f, x = 0.0f, y = 0.0f; void Draw() { glTranslatef(x,0,z); glColor3f(0.5f,0.5f,1.0f); // blue glBegin(GL_TRIANGLES); glVertex3f(-1.0f, 1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glEnd(); glColor3f(1.0f,0.5f,0.0f); // orange glBegin(GL_TRIANGLES); glVertex3f(-1.0f, 1.0f, -2.0f); glVertex3f( 1.0f, 1.0f, -2.0f); glVertex3f( 1.0f,-1.0f, -2.0f); glEnd(); } What I expect is 2 triangles one orange one blue with the orange one behind the blue one. (and indeed being obscured by it.). This isnt what happens though and even when i cange the signs on the z for the second triangle it remains visible. So i looked in the blue book and it told me to use glEnable(GL_DEPTH_TEST); and to clear my depth buffer. //glEnable(GL_DEPTH_TEST); glClearColor(0.0, 0.0, 0.0, 0.0); glClearDepth(0.0); while( g_Done == false ) { SDL_Event event; while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_QUIT ) g_Done = 1; } glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glLoadIdentity( ); Update(); Draw(); SDL_GL_SwapBuffers(); } this is what I tried. with glEnable() uncommented. I get a blank screen. I am very new to Opengl and 3d in general. some pointers to help me through this would be appreciated. As long as glEnable() is commented i see my triangles. I have googled, searched gamedev, and read upto chapter 7 in nehe's and quite a bit of blue book(which is a bit over my head but still quite useful).

Share this post


Link to post
Share on other sites
Advertisement
So a positive number for z is deeper? clearing my depth buffer to 20 worked. Thanks GD for helping me think this out myself.

Share this post


Link to post
Share on other sites
as chad saiz use
glClearDepth(1.0)
glEnable( GL_DEPTH_TEST );
glDEpthFunc( GL_LEQUAL );
glDepthMask( GL_TRUE );

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!