所以我正在将所有内容绘制到可调整大小的帧缓冲区中。
这是我的代码:
int main(int argc, char* argv[])
{
RUNNING = 1;
GLuint renderBuffer;
GLuint frameBuffer;
GLuint depthRenderBuffer;
// https://community.khronos.org/t/render-to-renderbuffer-with-depth-test/63793/3
glGenRenderbuffers( 1, &renderBuffer );
glBindRenderbuffer( GL_RENDERBUFFER, renderBuffer );
glRenderbufferStorage( GL_RENDERBUFFER, GL_RGB32F, RES_WIDTH, RES_HEIGHT );
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderBuffer);
// TODO: check for errors here
glGenRenderbuffers( 1, &depthRenderBuffer );
glBindRenderbuffer( GL_RENDERBUFFER, depthRenderBuffer );
glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT, RES_WIDTH, RES_HEIGHT );
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderBuffer);
// TODO: check for errors here
while(RUNNING)
{
glfwPollEvents();
glViewport(0, 0, RES_WIDTH, RES_HEIGHT);
glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
glClearColor(255, 255, 255, 1.0f);
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// drawing on screen
draw();
glBindFramebuffer(GL_READ_FRAMEBUFFER, frameBuffer);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(
0, 0, RES_WIDTH, RES_HEIGHT,
0, 0, window_width / 2, window_height / 2,
GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
glfwSwapBuffers(window);
}
return 0;
}
现在,问题在于它似乎正在绘制默认的绘制缓冲区和我的帧缓冲区。 这使所有内容看起来都很奇怪,这是屏幕截图:
因此,好像在默认渲染缓冲区上方绘制了我的帧缓冲区。
我的问题是:
如何使它仅绘制帧缓冲区,而不绘制其底下的内容?