I’ve wasted a couple of weeks trying to find the solution to this one, but as is sometimes the problem when searching online it’s often difficult to get the exact mix of keywords right before you start to yield any valid leads.
I was working with OpenFrameWorks on an application that generated a series of animated tiles. Because each tile needed to be individually rendered and masked I need to use a Fbo to render it off stage and then blend them all together as part of a final step. This was all working well until I tried to render some text into the Fbo. The Anti-Aliasing was terrible, something I initially put down to the font.
After a lot of testing I discovered that the Alpha channel in the Fbo was being treated in a very odd manor. As an example, if I filled a Fbo with a solid black color, then drew some white text I’d expect to have a texture that was completely solid (no transparency) with the white text anti aliased onto the black background. Drawing straight to stage without the Fbo indicated this was correct.
If I then took this Fbo and drew it to stage which had been filled red I would get a black background and white text (as expected) but instead the antialiasing around the text appeared as a blurry red edge. After a lot of testing I came to the conclusion that the alpha channel was being used to acheive the anti-aliasing around the text allowing the red background to show through.
I finally found this thread on the OpenFrameWorks Forum: https://forum.openframeworks.cc/index.php/topic,1643.0.html
It was the recommended solution by ‘blainer_s’ that worked for me:
void testApp::setup(){ image.loadImage("myPng.png"); //image is an ofImage, myPng.png is an image i created in photoshop real quick for testing texture.allocate(ofGetWidth(), ofGetHeight(), true); //texture is my ofxFBOTexture } //-------------------------------------------------------------- void testApp::update(){} //-------------------------------------------------------------- void testApp::draw(){ texture.begin(); ofEnableAlphaBlending(); image.draw(0, 0); ofDisableAlphaBlending(); texture.end(); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); //This is what is normally called with ofEnableAlphaBlending //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //if you have changed your blend equation, uncomment to return to default //glBlendEquation(GL_FUNC_ADD); texture.draw(0,0); glDisable(GL_BLEND); }
The important step being to change the blend function like so.
glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); //return to normal using //glBlendEquation(GL_FUNC_ADD);