Pre Z缓冲区通过OpenGL?

我怎样才能使用openGL进行Z缓冲预处理。

我试过这个:

glcolormask(0,0,0,0); //disable color buffer //draw scene glcolormask(1,1,1,1); //reenable color buffer //draw scene //flip buffers 

但它不起作用。 这样做后我什么也没看到。 有什么更好的方法呢?

谢谢

 // clear everything glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // z-prepass glEnable(GL_DEPTH_TEST); // We want depth test ! glDepthFunc(GL_LESS); // We want to get the nearest pixels glcolormask(0,0,0,0); // Disable color, it's useless, we only want depth. glDepthMask(GL_TRUE); // Ask z writing draw() // real render glEnable(GL_DEPTH_TEST); // We still want depth test glDepthFunc(GL_LEQUAL); // EQUAL should work, too. (Only draw pixels if they are the closest ones) glcolormask(1,1,1,1); // We want color this time glDepthMask(GL_FALSE); // Writing the z component is useless now, we already have it draw(); 

你正在使用glColorMask做正确的事情。

但是,如果你没有看到任何东西,可能是因为你使用了错误的深度测试function。 你需要GL_LEQUAL,而不是GL_LESS(这恰好是默认值)。

 glDepthFunc(GL_LEQUAL); 

如果我找到你,你试图禁用OpenGL执行的深度测试来确定剔除。 你在这里使用的是颜色function,这对我来说没有意义。 我想你正在努力做到以下几点:

 glDisable(GL_DEPTH_TEST); // disable z-buffer // draw scene glEnable(GL_DEPTH_TEST); // enable z-buffer // draw scene // flip buffers 

不要忘记在每次通过开始时清除深度缓冲区。