Jump to content
  • Advertisement
Sign in to follow this  
badkeeper3410

OpenGL Question of framebuffer and DepthTest

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

hello all. I have a question of the depthtest of opengl. In my recent scene,i want use the glDrawPixel to draw a backgroud of the scene,then i draw other staffs.But if i open the depthTest, the staffs render after glDrawPixel will not pass the test,and never draw.when i close the depthtest ,the staffs rendered,but with horrible looking. Is there any ways can solve these problem? sorry to my poor english,and thanks for help me :)

Share this post


Link to post
Share on other sites
Advertisement
You NEED render with depth test on!

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);

// draw your background image here!
glDrawPixel(...);

// and then, clear depth buffer with 1.0f(maximun depth value)
glClearDepth(1.0f);
glClear(GL_DEPTH_BUFFER_BIT);

// OK, draw your objects here! And all of them will pass the depth test
glBegin(...);
...
...
glEnd();

i hope it's useful!

Share this post


Link to post
Share on other sites
Clearing the buffer is not costless. A better approach is to disable the depth writing when rendering the background pixels. They do not need their depth value stored, because essentially they are always at infinity, i.e., anything is in front of them. I'm not a GL expert, but I'd suggest something along these lines:

glDisable( GL_DEPTH_WRITE );
RenderBackground();
glEnable( GL_DEPTH_WRITE );
RenderObjects();


Greetz,

Illco

Share this post


Link to post
Share on other sites
Thanks for the help.now I can render the scene with right way.
glDisable(GL_DEPTH_WRITEMASK);
RenderBackGroud();
glEnable(GL_DEPTH_WRITEMASK);

thanks again.

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!