Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Trouble understanding alpha blending when drawing in an FBO

$
0
0

@markwheeler wrote:

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 );
}

`

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles