the solution to this problem is to store the depth (z-axis) component of each FRAGMENT in a buffer(depth-buffer), and each and every time you want to write a fragment, you first check if you should (whether the new fragment is closer than the previous one in the depth buffer)..
you can do this yourself, but it's so much simpler to just ask the hardware to do it itself..
//enable depth test.and, you also need to clear the depth each frame, instead of only the color..
glEnable(GL_depth_test);
//accept fragment if it closer to the camera than the one in the depth buffer already.
glDepthFunc(GL_less);
//clear the screen buffer
glClear(GL_color_buffer_bit | GL_Depth_buffer_bit);
No comments:
Post a Comment