Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

problem saving openGL FBO larger than window

I'm rendering into an OpenGL offscreen framebuffer object and like to save it as an image. Note that the FBO is larger than the display size. I can render into the offscreen buffer and use it as texture, which works. I can "scroll" this larger texture through the display using an offset, which makes me confident, that I render into a larger context than the window.

If I save the offscreen buffer to an image file it always gets cropped. The code fragment for saving is:

void ofFBOTexture::saveImage(string fileName) { 
    glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); 
    // get the raw buffer from ofImage
    unsigned char* pixels = imageSaver.getPixels();
    glReadPixels(0, 0, 1024, 1024, GL_RGB, GL_UNSIGNED_BYTE, pixels); 

    imageSaver.saveImage(fileName); 
} 

Please note, that the image content is cropped, the visible part is saved correctly (which means no error in pixel formats, GL_RGB issues etc.), but the remaining space is filled with one color.

So, my question is - what am I doing wrong?

like image 476
razong Avatar asked Mar 25 '09 17:03

razong


1 Answers

Finally I solved the issue.

I have to activate the fbo for saving its contents:

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
// save code
...
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

while only selecting the fbo for glReadPixels via

glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);

doesn't suffice.

(All other things where correct and tested, eg. viewport sizes, width and height of buffer, image texture etc.)

like image 58
razong Avatar answered Sep 20 '22 12:09

razong