PDA

View Full Version : Writing out a FBO to image file issues



JohnMarkem
07-30-2014, 02:49 PM
I been trying to copy my FBO to file

My FBO looks like this:


glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorAttachment0, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthAttachment);

and my copy to file code looks like this:


glReadBuffer(GL_COLOR_ATTACHMENT0);
unsigned char* pixels3 = new unsigned char[(int)WIDTH * (int)HEIGHT * 4];
glReadPixels(0, 0, 800, 800, GL_RGBA, GL_UNSIGNED_BYTE, pixels3);
stbi_write_png("capture3.png", WIDTH, HEIGHT, 4, pixels3, WIDTH * 4);

But the image it write out is always black.