Trouble understanding alpha blending when drawing in an FBO

Hi,

I’m creating a simple frame buffer trail effect but I’m finding the alpha blending is not working how I would expect. Perhaps I’m misunderstanding how things are composited?

Here is a simplified example which draws a rect at startup, then draws black over it with low opacity every frame so it fades away. Except it doesn’t fade all the way – it stops getting visibly darker and just stays there.

Can anyone explain what’s going on?

Thx!

void ofApp::setup(){

    // Create FBO
    everythingFbo.allocate( ofGetWindowWidth(), ofGetWindowHeight() );

    // Draw a white rect on black in it
    everythingFbo.begin();
    ofClear( 0 );
    ofSetColor( 255 );
    ofDrawRectangle( 100, 100, 200, 200 );
    everythingFbo.end();
}

void ofApp::update(){
    // Nothing
}

void ofApp::draw(){

    // Darken everything in the FBO a bit every frame
    everythingFbo.begin();
    ofSetColor( 0, 2 );
    ofDrawRectangle( 0, 0, everythingFbo.getWidth(), everythingFbo.getHeight() );
    ofClearAlpha();
    everythingFbo.end();

    // Draw the FBO
    ofSetColor( 255 );
    everythingFbo.draw( 0, 0 );
}

`

I haven’t tried this code, but quickly sometimes you need to use a floating point texture to avoid rounding errors (you can’t do very subtle alpha things with regular 24 bit fbos). the fboTrails example shows how to allocate a floating point fbo to do better trails.

Ah and the example shows exactly what I’m looking for! Totally missed that, thanks for pointing me in the right direction :slight_smile: