ofFbo drawing affected by cleared color


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

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

In my code, as you can see I clear fbo with zero alpha, so the color should be invisible anyway.
But if I draw a circle onto the fbo, I can see the color still exist around the circle.

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

    fbo.draw(0, 0);
}

As you can see there is thin red outline.

If I clear it with the same color as the background color, then it looks clean but otherwise I think it always gets affected by the initial cleared color.
If It’s inevitable, would there be any trick to make the Fbo’d shape look clean regardless of the background color?


#2

I don’t think so –

the edges of the circle are transparent so they are getting blended w/ the red of the background and that’s why you see a red edge… those pixels have to get blended with something so I think you are going to have an issue no matter what but you might be able to find a blend mode for when you draw the white circle that does what you want (such as blending to white, etc) – vs regular alpha blending which is mixing the r/g/b of the incoming pixels (circle) and the dest pixel (background)…


#3

Thank you @zach

I think this fixed the unwanted outline.

ofPushStyle();
ofEnableBlendMode(OF_BLENDMODE_ADD);
fbo.draw(0, 0);
ofPopStyle();