c++ - Pre Z 缓冲区通过 OpenGL?

标签 c++ c 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();

关于c++ - Pre Z 缓冲区通过 OpenGL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3702984/

相关文章:

c - ubuntu - 寻找 IDE 编译器来构建和运行 .c 源文件,而无需创建项目

opengl - OpenGL/OpenGL ES 中的绑定(bind)点是什么?

opengl - GLSL固定功能片段程序替换

c++ - 在双链表数据结构类实验室项目中实现append和insertAt函数

c++ - 为什么每次成功的 QueryInterface() 调用之后都是 Release() 调用?

c++ - 2 个 pthread 条件变量可以共享同一个互斥锁吗?

c++ - 删除指向派生类的指针时指定给 RtlValidateHeap 的地址无效

c - 在 C 中迭代地反转字符串

c++ - glBindBuffer 崩溃 - 使用 glew 的 VBO 实现

c - 空指针赋值错误 union