void TextureSequenceOptimizer::renderImagesToFbo()
{
    // save size of loaded images
    int width = mTextureRefs[0]->getWidth();
    int height = mTextureRefs[0]->getHeight();
    
    mOriOutline = Area(0,0,width, height);
    
    // create fbo
    mFboRef = gl::Fbo::create(width, height, true);
    {
        // bind fbo
        gl::ScopedFramebuffer fbScp( mFboRef );
        
        // set viewport and matrices
        gl::ScopedViewport scpVp( ivec2( 0 ), mFboRef->getSize() );
        gl::ScopedMatrices matricesFbo;
        gl::setMatricesWindow(width, height);
        
        // clear fbo and draw images
        gl::clear(ColorA(0, 0, 0, 0));
        gl::color(1, 1, 1);
        
        // draw images on fbo
        for (gl::TextureRef tex: mTextureRefs) {
            gl::draw(tex);
        }
        
    }
    //read overlayed texuture from fbo
    mResultTextureRef = mFboRef->getColorTexture();
    
    trim();
}
void SystemCinderApp::renderSceneToFbo()
{
	gl::ScopedFramebuffer fbScp(mFbo);
	gl::clear(Color(0, 0, 0));

	//set the viewport to match the dimensions of the FBO;
	gl::ScopedViewport scVprt(ivec2(0), mFbo->getSize());

	gl::setMatrices(mCamFbo);

	drawScene();
}
	ci::gl::Texture2dRef VDFbo::getFboTexture() {
		// TODO move this:
		getShader();
		//iChannelResolution0 = vec3(mPosX, mPosY, 0.5);
		gl::ScopedFramebuffer fbScp(mFbo);
		gl::clear(Color::black());
		// TODO check mTextureList size for bounds
		if (mInputTextureIndex > mTextureList.size() - 1) mInputTextureIndex = 0;
		mTextureList[mInputTextureIndex]->getTexture()->bind(0);

		gl::ScopedGlslProg glslScope(mFboTextureShader);
		gl::drawSolidRect(Rectf(0, 0, mVDSettings->mFboWidth, mVDSettings->mFboHeight));

		mRenderedTexture = mFbo->getColorTexture();
		return mRenderedTexture;
	}