Question of framebuffer and DepthTest

Started by
2 comments, last by badkeeper3410 18 years, 10 months ago
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 :)
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!
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
Thanks for the help.now I can render the scene with right way.
glDisable(GL_DEPTH_WRITEMASK);
RenderBackGroud();
glEnable(GL_DEPTH_WRITEMASK);

thanks again.

This topic is closed to new replies.

Advertisement