gpt4 book ai didi

opengl - 渲染到离屏缓冲区然后渲染到纹理时如何使用深度测试

转载 作者:行者123 更新时间:2023-12-02 08:13:29 25 4
gpt4 key购买 nike

我正在将场景渲染为纹理。除了深度测试不起作用之外,这工作得很好。如果渲染到离屏纹理,如何启用深度测试?我正在使用 FrameBuffer 类 http://www.opengl.org/news/comments/framebuffer_object_fbo_c_class_available_with_example_application/

glGetIntegerv(GL_DRAW_BUFFER, &drawBuffer);
frameBuffer->Bind();
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
rAngle += 0.3f;
glUseProgram(0);
drawSpinningTeapot();
FramebufferObject::Disable();

glDrawBuffer(drawBuffer);
glViewport(0, 0, WINDOW_WIDTH,WINDOW_HEIGHT);
glClear(GL_COLOR_BUFFER_BIT);

glUseProgram(g_program);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,tex1);
texSampler = glGetUniformLocation(g_program,"texture");
glUniform1f(texSampler, 0);
glActiveTexture(GL_TEXTURE0);
glBegin(GL_QUADS);
{
glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f);
glTexCoord2f(1, 0); glVertex3f( 1, -1, -0.5f);
glTexCoord2f(1, 1); glVertex3f( 1, 1, -0.5f);
glTexCoord2f(0, 1); glVertex3f(-1, 1, -0.5f);
}
glEnd();
glDisable(GL_TEXTURE_2D);

最佳答案

除了颜色附件之外,您还需要将渲染缓冲区或纹理附加到GL_DEPTH_ATTACHMENT。这是一个很好的入门教程:

http://www.songho.ca/opengl/gl_fbo.html

关于opengl - 渲染到离屏缓冲区然后渲染到纹理时如何使用深度测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5751081/

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