Andrea
1
I can’t get the the blending working inside the fbo, any suggestions?
thanks.
gl::enableBlending(true);
gl::enableAdditiveBlending();
gl::begin( GL_TRIANGLES );
gl::color( ColorA( 1.0f, 0.0f, 0.0f, 1.0f ) );
gl::vertex( vec2(0,0) );
gl::vertex( vec2(100,0) );
gl::vertex( vec2(100,100) );
gl::color( ColorA( 0.0f, 1.0f, 0.0f, 1.0f ) );
gl::vertex( vec2(50,0) );
gl::vertex( vec2(500,0) );
gl::vertex( vec2(200,50) );
gl::end();
return fbo->getColorTexture();
Make sure to clear the alpha channel as well:
gl::clear( ColorA( 0, 0, 0, 0 ) );
Edit: I tried your code and that just works, as long as you make sure to properly bind and unbind the Fbo
.
auto fbo = gl::Fbo::create( getWindowWidth(), getWindowHeight(), true, false );
{
gl::ScopedFramebuffer scpFbo( fbo );
gl::ScopedBlendAdditive scpBlend;
gl::clear( ColorA( 0, 0, 0, 0 ) );
gl::begin( GL_TRIANGLES );
gl::ScopedColor scpColor( ColorA( 1.0f, 0.0f, 0.0f, 1.0f ) );
gl::vertex( vec2( 0, 0 ) );
gl::vertex( vec2( 100, 0 ) );
gl::vertex( vec2( 100, 100 ) );
gl::color( ColorA( 0.0f, 1.0f, 0.0f, 1.0f ) );
gl::vertex( vec2( 50, 0 ) );
gl::vertex( vec2( 500, 0 ) );
gl::vertex( vec2( 200, 50 ) );
gl::end();
}
gl::draw( fbo->getColorTexture() );
Andrea
3
thanks paul, it looks like it only works if I use ScopedColor, if I set it using gl::color the blending doesn’t work. any idea why?
No, that does not make any sense to me - in all cases the context’s current color is used so it should work with either gl::color
or gl::ScopedColor
.