ofPolyline not affected by alpha in FBO

I’m trying to leave trails in my animations, and since I have some flickering problems using ofSetBackgroundAuto(false); (see the issue in this link), I’ve been trying to use FBOs.

It works fine when using simple 2D primitives or ofBeginShape(); but when I try an ofPolyline it doesn’t work.

Here you can see the a screenshot and the code I’m using with the ofBeginShape() and the ofPolyline side by side:

//--------------------------------------------------------------
void ofApp::setup(){
    
    ofSetBackgroundAuto(false);
    width = ofGetWidth();
    height = ofGetHeight();
    fbo.allocate(width, height, GL_RGBA);
    
    fbo.begin();
    ofClear(0, 0, 0, 255);
    fbo.end();
    
    offset = ofRandom(100);

}

//--------------------------------------------------------------
void ofApp::update(){
    
    offset += 0.01;

}

//--------------------------------------------------------------
void ofApp::draw(){
    
    drawFBO();
    fbo.draw(0, 0);
    
}

//--------------------------------------------------------------
void ofApp::drawFBO(){
    
    fbo.begin();
    
    ofSetColor(0, 0, 0, 40);
    ofDrawRectangle(0, 0, width, height);
    
    ofNoFill();
    ofSetColor(255);
    
    ofPushMatrix();
    
    ofTranslate(width * 0.5, height * 0.5);
    
    ofBeginShape();
    
    int resolution = 60;
    float radius = 100;
    float noiseHeight = 20;
    
    for (int i = 0; i < resolution; i++) {
        
        float angle = ofMap(i, 0, resolution, 0, PI * 2);
        
        float x = cos(angle) * (radius + ofNoise(i, offset) * noiseHeight);
        float y = sin(angle) * (radius + ofNoise(i, offset) * noiseHeight);
        
        ofVertex(x - 200, y);
        straightSegmentPolyline.addVertex(x + 200, y);
    }
    
    ofEndShape(true);
    
    straightSegmentPolyline.draw();
    
    ofPopMatrix();
    
    fbo.end();
}

Any help will be welcomed, thanks!

Hi there!

Before make another call to your FBO, you need to clean you ofPolyline. Like so:

    straightSegmentPolyline.clear();

Otherwise, you just keep adding points to it.

1 Like

Also, try clearing your FBO with ofClear(0, 0, 0, 0) which will start you off with a transparent FBO ready to have non transparent things drawn into it.

(Actually, reading properly through your code that wouldn’t change anything, @hubris suggestion should solve it )

1 Like

Thanks! It works just fine now :slight_smile: