Reallocating FBO with different format doesn't work properly


#1

I don’t understand why reallocating FBO doesn’t work properly.
Please look at my example code below,
in setup() I allocated an FBO with GL_RGB format and then cleared it with red color.
And then in draw(), I drew a white circle onto the FBO.
And if I press any key, it will re-allocate FBO with GL_RGBA format and then clear it with 0,0,0,0 which should make the FBO transparent.
But what I see is a black background and not transparent.
Is this a natural behaviour?

//--------------------------------------------------------------
void ofApp::setup(){

    fbo.allocate(400, 400, GL_RGB);
    fbo.begin();
    ofClear(ofColor(255,0,0));
    fbo.end();
}

//--------------------------------------------------------------
void ofApp::draw(){
    
    fbo.begin();
    ofSetColor(255, 255, 255);
    ofSetCircleResolution(50);
    ofDrawCircle(200, 200, 200);
    fbo.end();

    fbo.draw(0, 0);
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){

    fbo.allocate(400, 400, GL_RGBA);
    fbo.begin();
    ofClear(ofColor(0,0,0,0));
    fbo.end();
}

Before key press

After key press

Also, the opposite way doesn’t work properly either (GL_RGBA -> GL_RGB)
In this case, if I reallocate FBO with GL_RGB, and then if I clear color with 0,0,0,0 the background becomes transparent which it should not be.

I think it means once FBO is allocated with a specific format, the format never changes even if it is reallocated. I wonder if it is a natural behaviour or a bug.


#2

that’s probably a bug. since reallocating an fbo is not very common it’s probably gone undetected. can you open an issue on github?


#3

Cheers!
https://github.com/openframeworks/openFrameworks/issues/5559