Skip to content

Instantly share code, notes, and snippets.

@elliotwoods
Forked from HalfdanJ/alphafbo.cpp
Created May 26, 2016 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elliotwoods/21678df10d02ef0197121281e8ce4da8 to your computer and use it in GitHub Desktop.
Save elliotwoods/21678df10d02ef0197121281e8ce4da8 to your computer and use it in GitHub Desktop.
ofFbo with premultiplied alpha
// Kudos to armadilly
fbo.begin();
{
///pre-multiply background color of the fbo for correct blending!
ofClear(ofColor(fboBgColor * (fboBgColor.a / 255.) , fboBgColor.a));
//Set this blending mode for anything you draw INSIDE the fbo
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
//your draw code here!
}
fbo.end();
//then draw the fbo to your screen buffer with this blending
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
fbo.draw(0,0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment