Hi. I’m trying to render to multiple FBOs with texture storage. Ultimately, the rendered content will change for each, so multiple render targets is not an option. However, with N FBOs, only the last contains the correct color data. Every prior texture contains the default framebuffer color data in a viewport whose size is the same as the default framebuffer’s. What would cause this?
Here’s the FBO initialization:
glGenFramebuffers(3, fids);
glGenTextures(3, tids);
for (int i = 0; i < 3; ++i) {
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fids[i]);
glActiveTexture(GL_TEXTURE0 + i);
glBindTexture(GL_TEXTURE_2D, tids[i]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1024, 1024, 0, GL_RGBA, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tids[i], 0);
}
The framebuffers are framebuffer complete. Here’s the drawing routine:
for (int i = 0; i < 3; i++) {
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fids[i]);
glViewport(0, 0, 1024, 1024);
glClear(GL_COLOR_BUFFER_BIT);
// render a bunch of lines in white
}
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
// render a bunch of lines in red
And that leads to this result:
Only the last FBO’s texture is correct. The others contain the default FBO content, sized at 512x512.
Your wisdom is appreciated.
- Chris