我正在尝试渲染到 fbo,然后将该纹理用作我的第二个渲染通道的输入以进行后期处理,但似乎会glClear
影响glClearColor
已渲染到的纹理。我怎样才能让它们只影响显示缓冲区?
我的代码看起来像这样:
UseRenderingShaderProgram();
glBindFramebuffer(GL_FRAMEBUFFER, fb);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
renderWorld();
// render to screen
UsePostProcessingShaderProgram();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClearColor(0.0, 0.0, 0.0, 1.0); // <== texture appears to get cleared in this two lines.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
renderWorld();
glfwSwapBuffers();