I can’t figure out how I correctly manage transparency when using FBO.
I want to draw some rects and circles blended on an FBO and to make the FBO blend with other graphic elements drawn directly on the screen.
The code attached below is an example:
There are three elements : an FBO where two circles are blended, two other circles drawn on the screen the same way, and a rectangle drawn in the bottom area of the screen.
With this code, I get the right result except the colors of two circles on the FBO are not correct.
Using ofDisableAlphaBlending(); I got the right colors but the rectangle is not blended correctly. (Changing the order of drawing is not the solution I want here.)
Using glBlendFuncSeparate(); I got various results but I have no idea what combination of the parameters I have to use.
Please help me.
Thanks a lot!
void ofApp::draw() {
// in setup()
// set to background to (200, 200, 0)
// create an fbo
ofFbo fbo;
fbo.allocate(ofGetWidth() / 2, ofGetHeight());
// draw a gray box at the bottom
ofSetRectMode(OF_RECTMODE_CORNER);
ofSetColor(100);
ofRect(50, ofGetHeight() - 150, ofGetWidth() - 100, 100);
////////////////////////////////////////
// draw on FBO and copy to the screen //
////////////////////////////////////////
// setup
fbo.begin();
ofClear(0, 0, 0, 0);
// draw two circles
ofSetColor(205, 50, 50, 80);
ofCircle(200, 200, 100);
ofCircle(250, 250, 100);
// end
fbo.end();
ofSetColor(255);
fbo.draw(0, 0);
/////////////////////////////////
// draw directly on the screen //
/////////////////////////////////
// setup
ofPushMatrix();
ofTranslate(ofGetWidth() / 2, 0);
// draw two circles
ofSetColor(205, 50, 50, 50);
ofCircle(200, 200, 100);
ofCircle(250, 250, 100);
// end
ofPopMatrix();
}