Hey @lithium and @paul.houx - thank you both for taking the time to respond to me.
I’ve learned a whole lot from looking at various samples, and websites. The one thing that I’ve yet to figure out, is how to do the ping pong technique using only a single FBO. The various threads I’ve read lead me to believe that this is supposedly the ideal approach.
Thanks to the FboMultipleRenderTargets sample, I’ve seen how to attach more than one texture to an FBO as follows:
auto fboFormat = ci::gl::Fbo::Format()
.attachment( GL_COLOR_ATTACHMENT0, gl::Texture2d::create( renderWidth, renderHeight ) )
.attachment( GL_COLOR_ATTACHMENT1, gl::Texture2d::create( renderWidth, renderHeight ) );
mFboRef = ci::gl::Fbo::create( renderWidth, renderHeight, fboFormat );
Using the code below, I can attach either of the two and render into either texture succesfully:
{
ci::gl::ScopedFramebuffer fbScp( mFboRef );
ci::gl::ScopedGlslProg glslScp( mGlslPixelate );
mGlslPixelate->uniform( "uPixelSize", 50.0f );
ci::gl::ScopedTextureBind texScp( mTexRef );
gl::drawBuffer( GL_COLOR_ATTACHMENT0 );
gl::clear( Color( 0, 0, 1 ) );
ci::gl::drawSolidRect( ci::Rectf( 0, 0, 300, 300 ) );
}
ci::gl::draw( mFboRef->getTexture2d( GL_COLOR_ATTACHMENT0 ), ci::Rectf( 0, 0, 640, 480 ) );
Exchanging GL_COLOR_ATTACHMENT0
for GL_COLOR_ATTACHMENT1
works fine, which I take it means rendering into either attachment is fine. However, taking things one step further fails Here’s my attempt at rendering 2 different passed with a different fragment shader:
{
ci::gl::ScopedFramebuffer fbScp( mFboRef );
ci::gl::ScopedGlslProg glslScp( mGlslPixelate );
mGlslPixelate->uniform( "uPixelSize", 50.0f );
//ci::gl::ScopedGlslProg glslScp( mGlslDither );
//ci::gl::ScopedGlslProg glslScp( mGlslC64 );
ci::gl::ScopedTextureBind texScp( mTexRef );
gl::drawBuffer( GL_COLOR_ATTACHMENT0 );
gl::clear( Color( 0, 0, 1 ) );
ci::gl::drawSolidRect( ci::Rectf( 0, 0, 300, 300 ) );
}
// Switch attachments, hook up next new shader
{
ci::gl::ScopedFramebuffer fbScp( mFboRef );
ci::gl::ScopedGlslProg glslScp( mGlslC64 );
ci::gl::ScopedTextureBind( mFboRef->getTexture2d( GL_COLOR_ATTACHMENT0 ) );
gl::drawBuffer( GL_COLOR_ATTACHMENT1 );
gl::clear( Color( 1, 0, 0 ) );
// No clear this time
ci::gl::drawSolidRect( ci::Rectf( 0, 0, 640, 480 ) );
}
ci::gl::draw( mFboRef->getTexture2d( GL_COLOR_ATTACHMENT1 ), ci::Rectf( 0, 0, 640, 480 ) );
As you can see, I attach the FBO’s previous output texture (GL_COLOR_ATTACHMENT0
), and try to draw in the GL_COLOR_ATTACHMENT1
. This unfortunately just spits out black. Any ideas as to what might be going wrong would be much appreciated!
Cheers!