Skip to content

Instantly share code, notes, and snippets.

@Samsy
Forked from HalfdanJ/alphafbo.cpp
Created June 3, 2016 13:16
Show Gist options
  • Save Samsy/556067571bd98ec7d314b3f21a34d54b to your computer and use it in GitHub Desktop.
Save Samsy/556067571bd98ec7d314b3f21a34d54b 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