How to write to the OpenGL Depth Buffer

馋奶兔 提交于 2019-12-05 12:22:10

After trying to get a depth texture to work, I then tried the ARB_fragment_program extension to see if I could write a very simple (and therefore widely compatible with old hardware) GPU assembly fragment shader to do the trick, but I eventually just decided to use GLSL as the ARB_fragment_program extensions seem to be deprecated or at least their usage is frowned upon nowadays.

You can try using frame buffer objects to do what you want.

Create fbo1 and attach a color and depth buffer. Render or set the scene for the background.

Create fbo2 and attach a color and depth buffer.

Use frame buffer blit at each update to blit the color and depth buffers from fbo1 to fbo2.

Render the rest into fbo2

Do a full screen blit of fbo2 color buffer to the main display buffer.

genpfault

Disable writing to the color buffer (use: glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE), then render polygons representing your "in-front" image with an appropriate Z-coordinate.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!