gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 17:14:31 24 4
gpt4 key购买 nike

我如何使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com