// Render the torus into the FBO void FBOMultipleTargetsApp::renderSceneToFbo() { // bind the framebuffer - now everything we draw will go there mFbo.bindFramebuffer(); // setup the viewport to match the dimensions of the FBO gl::setViewport( mFbo.getBounds() ); // setup our camera to render the torus scene CameraPersp cam( mFbo.getWidth(), mFbo.getHeight(), 60.0f ); cam.setPerspective( 60, mFbo.getAspectRatio(), 1, 1000 ); cam.lookAt( Vec3f( 2.8f, 1.8f, -2.8f ), Vec3f::zero() ); gl::setMatrices( cam ); // set the modelview matrix to reflect our current rotation gl::multModelView( mTorusRotation ); // clear out both of the attachments of the FBO with black gl::clear(); // render the torus with our multiple-output shader mShaderMultipleOuts.bind(); gl::drawTorus( 1.4f, 0.3f, 32, 64 ); mShaderMultipleOuts.unbind(); // unbind the framebuffer, so that drawing goes to the screen again mFbo.unbindFramebuffer(); }
// Render the torus into the FBO void FBOBasicApp::renderSceneToFbo() { // this will restore the old framebuffer binding when we leave this function // on non-OpenGL ES platforms, you can just call mFbo.unbindFramebuffer() at the end of the function // but this will restore the "screen" FBO on OpenGL ES, and does the right thing on both platforms gl::SaveFramebufferBinding bindingSaver; // bind the framebuffer - now everything we draw will go there mFbo.bindFramebuffer(); // setup the viewport to match the dimensions of the FBO gl::setViewport( mFbo.getBounds() ); // setup our camera to render the torus scene CameraPersp cam( mFbo.getWidth(), mFbo.getHeight(), 60.0f ); cam.setPerspective( 60, mFbo.getAspectRatio(), 1, 1000 ); cam.lookAt( Vec3f( 2.8f, 1.8f, -2.8f ), Vec3f::zero() ); gl::setMatrices( cam ); // set the modelview matrix to reflect our current rotation gl::multModelView( mTorusRotation ); // clear out the FBO with blue gl::clear( Color( 0.25, 0.5f, 1.0f ) ); // render an orange torus, with no textures glDisable( GL_TEXTURE_2D ); gl::color( Color( 1.0f, 0.5f, 0.25f ) ); gl::drawTorus( 1.4f, 0.3f, 32, 64 ); // gl::drawColorCube( Vec3f::zero(), Vec3f( 2.2f, 2.2f, 2.2f ) ); }