Question of framebuffer and DepthTest
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 :)
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!
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:
Greetz,
Illco
glDisable( GL_DEPTH_WRITE );RenderBackground();glEnable( GL_DEPTH_WRITE );RenderObjects();
Greetz,
Illco
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement