Example #1
0
// 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();
}
Example #2
0
void ChargesApp::setup()
{
	//gl::disableVerticalSync();

	gl::Fbo::Format format;
	format.enableDepthBuffer( false );
	format.setSamples( 4 );

	mFbo = gl::Fbo( 1280, 800, format );
	mKawaseBloom = mndl::gl::fx::KawaseBloom( mFbo.getWidth(), mFbo.getHeight() );

	mEffectCharge.setup();
	mEffectCharge.instantiate();
	mEffectCharge.setBounds( mFbo.getBounds() );

	// Leap
	mLeap = LeapSdk::Device::create();
	mLeapCallbackId = mLeap->addCallback( &ChargesApp::onFrame, this );

	// params
	mndl::kit::params::PInterfaceGl::load( "params.xml" );
	mParams = mndl::kit::params::PInterfaceGl( "Parameters", Vec2i( 200, 300 ) );
	mParams.addPersistentSizeAndPosition();
	mParams.addParam( "Fps", &mFps, "", true );
	mParams.addSeparator();
	mParams.addPersistentParam( "Line width", &mLineWidth, 4.5f, "min=.5 max=10 step=.1" );
	mParams.addPersistentParam( "Bloom strength", &mBloomStrength, .8f, "min=0 max=1 step=.05" );
	mParams.addPersistentParam( "Finger disapperance thr", &mFingerDisapperanceThreshold, .1f, "min=0 max=2 step=.05" );

	mndl::kit::params::PInterfaceGl::showAllParams( false );
}
void HiKinectApp::generateNormalMap() {
	// bind the Fbo
	mFbo.bindFramebuffer();
	// match the viewport to the Fbo dimensions
	gl::setViewport( mFbo.getBounds() );
	// setup an ortho projection
	gl::setMatricesWindow( mFbo.getWidth(), mFbo.getHeight() );
	// clear the Fbo
	gl::clear( Color( 0, 0, 0 ) );
	
	// bind the shader, set its variables
	mNormalShader.bind();
	mNormalShader.uniform( "normalStrength", mNormalStrength);
	mNormalShader.uniform( "texelWidth", 1.0f / (float)CAPTURE_WIDTH );
	
	if ( mDepthTexture ) {
		gl::pushModelView();
//		gl::translate( Vec3f( 0, mDepthTexture.getHeight(), 0 ) );
//		gl::scale( Vec3f( 1, -1, 1 ) );
		gl::draw( mDepthTexture );
		gl::popModelView();
	}
	
	// unbind the shader
	mNormalShader.unbind();
	// unbind the Fbo
	mFbo.unbindFramebuffer();
}
Example #4
0
// 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 ) );
}
void ScreenShadersApp::draw()
{
	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) ); 
	
	// bind the Fbo
	mFbo.bindFramebuffer();
	// match the viewport to the Fbo dimensions
	gl::setViewport( mFbo.getBounds() );
	// setup an ortho projection
	gl::setMatricesWindow( mFbo.getWidth(), mFbo.getHeight() );
	// clear the Fbo
	gl::clear( Color( 0, 0, 0 ) );
	
	if ( mTexture ) {
		gl::draw( mTexture );
	}
	
	// unbind the Fbo
	mFbo.unbindFramebuffer();
	
	gl::setMatricesWindow( getWindowWidth(), getWindowHeight() );
	
	float kernelRes = 21.0f;
	
	mBlurShader.bind();
	mBlurShader.uniform( "kernelRes", kernelRes );
	mBlurShader.uniform( "invKernelRes", 1.0f / kernelRes );
	mBlurShader.uniform( "fboTex", 0 );
	mBlurShader.uniform( "kernelTex", 1 );
	mBlurShader.uniform( "orientationVector", Vec2f( 1.0f, 1.0f ) );
	mBlurShader.uniform( "blurAmt", 1.0f );
	mBlurShader.uniform( "colMulti", 1.0f );
	
	mBlurKernel.bind( 1 );
	
	gl::draw( mFbo.getTexture(0), Rectf( 0, getWindowHeight(), getWindowWidth(), 0 ) );
	mBlurShader.unbind();
}
void BloomingNeonApp::draw()
{
	// clear our window
	gl::clear( Color::black() );

	// store our viewport, so we can restore it later
	Area viewport = gl::getViewport();

	// render scene into mFboScene using illumination texture
	mTextureIllumination.enableAndBind();
	mTextureSpecular.bind(1);
	gl::setViewport( mFboScene.getBounds() );
	mFboScene.bindFramebuffer();
		gl::pushMatrices();
			gl::setMatricesWindow(SCENE_SIZE, SCENE_SIZE, false);
			gl::clear( Color::black() );
			render();
		gl::popMatrices();
	mFboScene.unbindFramebuffer();

	// bind the blur shader
	mShaderBlur.bind();
	mShaderBlur.uniform("tex0", 0); // use texture unit 0
 
	// tell the shader to blur horizontally and the size of 1 pixel
	mShaderBlur.uniform("sample_offset", Vec2f(1.0f/mFboBlur1.getWidth(), 0.0f));
	mShaderBlur.uniform("attenuation", 2.5f);

	// copy a horizontally blurred version of our scene into the first blur Fbo
	gl::setViewport( mFboBlur1.getBounds() );
	mFboBlur1.bindFramebuffer();
		mFboScene.bindTexture(0);
		gl::pushMatrices();
			gl::setMatricesWindow(BLUR_SIZE, BLUR_SIZE, false);
			gl::clear( Color::black() );
			gl::drawSolidRect( mFboBlur1.getBounds() );
		gl::popMatrices();
		mFboScene.unbindTexture();
	mFboBlur1.unbindFramebuffer();	
 
	// tell the shader to blur vertically and the size of 1 pixel
	mShaderBlur.uniform("sample_offset", Vec2f(0.0f, 1.0f/mFboBlur2.getHeight()));
	mShaderBlur.uniform("attenuation", 2.5f);

	// copy a vertically blurred version of our blurred scene into the second blur Fbo
	gl::setViewport( mFboBlur2.getBounds() );
	mFboBlur2.bindFramebuffer();
		mFboBlur1.bindTexture(0);
		gl::pushMatrices();
			gl::setMatricesWindow(BLUR_SIZE, BLUR_SIZE, false);
			gl::clear( Color::black() );
			gl::drawSolidRect( mFboBlur2.getBounds() );
		gl::popMatrices();
		mFboBlur1.unbindTexture();
	mFboBlur2.unbindFramebuffer();

	// unbind the shader
	mShaderBlur.unbind();

	// render scene into mFboScene using color texture
	mTextureColor.enableAndBind();
	mTextureSpecular.bind(1);
	gl::setViewport( mFboScene.getBounds() );
	mFboScene.bindFramebuffer();
		gl::pushMatrices();
			gl::setMatricesWindow(SCENE_SIZE, SCENE_SIZE, false);
			gl::clear( Color::black() );
			render();
		gl::popMatrices();
	mFboScene.unbindFramebuffer();

	// restore the viewport
	gl::setViewport( viewport );

	// because the Fbo's have their origin in the LOWER-left corner,
	// flip the Y-axis before drawing
	gl::pushModelView();
	gl::translate( Vec2f(0, 256) );
	gl::scale( Vec3f(1, -1, 1) );

	// draw the 3 Fbo's 
	gl::color( Color::white() );
	gl::draw( mFboScene.getTexture(), Rectf(0, 0, 256, 256) );
	drawStrokedRect( Rectf(0, 0, 256, 256) );

	gl::draw( mFboBlur1.getTexture(), Rectf(260, 0, 260 + 256, 256) );
	drawStrokedRect( Rectf(260, 0, 260 + 256, 256) );

	gl::draw( mFboBlur2.getTexture(), Rectf(520, 0, 520 + 256, 256) );
	drawStrokedRect( Rectf(520, 0, 520 + 256, 256) );

	// draw our scene with the blurred version added as a blend
	gl::color( Color::white() );
	gl::draw( mFboScene.getTexture(), Rectf(780, 0, 780 + 256, 256) );

	gl::enableAdditiveBlending();
	gl::draw( mFboBlur2.getTexture(), Rectf(780, 0, 780 + 256, 256) );
	gl::disableAlphaBlending();
	drawStrokedRect( Rectf(780, 0, 780 + 256, 256) );
	
	// restore the modelview matrix
	gl::popModelView();

	// draw info
	gl::enableAlphaBlending();
	gl::drawStringCentered("Basic Scene", Vec2f(128, 236));
	gl::drawStringCentered("First Blur Pass (Horizontal)", Vec2f(260 + 128, 236));
	gl::drawStringCentered("Second Blur Pass (Vertical)", Vec2f(520 + 128, 236));
	gl::drawStringCentered("Final Scene", Vec2f(780 + 128, 236));
	gl::disableAlphaBlending();
}
Example #7
0
void StarsApp::draw()
{		
	int w = getWindowWidth();
	int h = getWindowHeight();

	gl::clear( Color::black() ); 

	if(mIsStereoscopic) {
		glPushAttrib( GL_VIEWPORT_BIT );
		gl::pushMatrices();

		// render left eye
		mCamera.enableStereoLeft();

		gl::setViewport( Area(0, 0, w / 2, h) );
		gl::setMatrices( mCamera.getCamera() );
		render();
	
		// draw user interface
		mUserInterface.draw("Stereoscopic Projection");

		// render right eye
		mCamera.enableStereoRight();

		gl::setViewport( Area(w / 2, 0, w, h) );
		gl::setMatrices( mCamera.getCamera() );
		render();
	
		// draw user interface
		mUserInterface.draw("Stereoscopic Projection");

		gl::popMatrices();		
		glPopAttrib();
	}
	else if(mIsCylindrical) {
		// make sure we have a frame buffer to render to
		createFbo();

		// determine correct aspect ratio and vertical field of view for each of the 3 views
		w = mFbo.getWidth() / 3;
		h = mFbo.getHeight();

		const float aspect = float(w) / float(h);
		const float hFoV = 60.0f;
		const float vFoV = toDegrees( 2.0f * math<float>::atan( math<float>::tan( toRadians(hFoV) * 0.5f ) / aspect ) );

		// for values smaller than 1.0, this will cause each view to overlap the other ones
		const float overlap = 1.0f;	

		// bind the frame buffer object
		mFbo.bindFramebuffer();

		// store viewport, camera and matrices, so we can restore later
		glPushAttrib( GL_VIEWPORT_BIT );
		CameraStereo original = mCamera.getCamera();
		gl::pushMatrices();

		// setup camera	
		CameraStereo cam = mCamera.getCamera();
		cam.disableStereo();
		cam.setAspectRatio(aspect);
		cam.setFov( vFoV );

		Vec3f right, up;	
		cam.getBillboardVectors(&right, &up);
		Vec3f forward = up.cross(right);

		// render left side
		gl::setViewport( Area(0, 0, w, h) );

		cam.setViewDirection( Quatf(up, overlap * toRadians(hFoV)) * forward );
		cam.setWorldUp( up );
		gl::setMatrices( cam );
		render();
		
		// render front side
		gl::setViewport( Area(w, 0, w*2, h) );

		cam.setViewDirection( forward );
		cam.setWorldUp( up );
		gl::setMatrices( cam );
		render();	
	
		// draw user interface
		mUserInterface.draw( (boost::format("Cylindrical Projection (%d degrees)") % int( (1.0f + 2.0f * overlap) * hFoV ) ).str() );

		// render right side
		gl::setViewport( Area(w*2, 0, w*3, h) );

		cam.setViewDirection( Quatf(up, -overlap * toRadians(hFoV)) * forward );
		cam.setWorldUp( up );
		gl::setMatrices( cam );
		render();
		
		// unbind the frame buffer object
		mFbo.unbindFramebuffer();

		// restore states
		gl::popMatrices();		
		mCamera.setCurrentCam(original);
		glPopAttrib();

		// draw frame buffer and perform cylindrical projection using a fragment shader
		if(mShader) {
			float sides = 3;
			float radians = sides * toRadians( hFoV );
			float reciprocal = 0.5f / sides;

			mShader.bind();
			mShader.uniform("texture", 0);
			mShader.uniform("sides", sides);
			mShader.uniform("radians", radians );
			mShader.uniform("reciprocal", reciprocal );
		}

		Rectf centered = Rectf(mFbo.getBounds()).getCenteredFit( getWindowBounds(), false );
		gl::draw( mFbo.getTexture(), centered );

		if(mShader) mShader.unbind();
	}
	else {
		mCamera.disableStereo();

		gl::pushMatrices();
		gl::setMatrices( mCamera.getCamera() );
		render();
		gl::popMatrices();
	
		// draw user interface
		mUserInterface.draw("Perspective Projection");
	}

	// fade in at start of application
	gl::enableAlphaBlending();
	double t = math<double>::clamp( mTimer.getSeconds() / 3.0, 0.0, 1.0 );
	float a = ci::lerp<float>(1.0f, 0.0f, (float) t);

	if( a > 0.0f ) {
		gl::color( ColorA(0,0,0,a) );
		gl::drawSolidRect( getWindowBounds() );
	}
	gl::disableAlphaBlending();
}
Example #8
0
void TextTestApp::draw()
{
	// this pair of lines is the standard way to clear the screen in OpenGL
	glClearColor( 0,0,0,1 );
	glClear( GL_COLOR_BUFFER_BIT );
	
	if (flipScreen==true){
		gl::pushMatrices();
		
		gl::scale( Vec3f(-1, 1, 1) );
		gl::translate( Vec2f(-ci::app::getWindowWidth(), 0 ) );
		gl::translate( Vec3f(-1, 1, 1) );
	}

	gl::enableAlphaBlending();
	gl::enableAdditiveBlending();

	mbackground.draw();

	drawSkeleton();

	// FONT NOW GETS RENDERED AFTER SCENE SO WE CAN OVERRIDE DRAW OPERATION IF REQUIRED
	currentScene->draw();

	myFont.draw();	
	
	// kill this all and refresh
	gl::disableAlphaBlending();
	gl::enableAdditiveBlending();

	// store our viewport, so we can restore it later
	Area viewport = gl::getViewport();

	// render a simple scene into mFboScene
	gl::setViewport( mFboScene.getBounds() );
	mFboScene.bindFramebuffer();
		gl::pushMatrices();
		gl::setMatricesWindow( viewport.getWidth(), viewport.getHeight(), false );
			gl::clear( ColorA( 0,0,0,1 ));
			fgParticles.draw();
			//gl::drawSolidCircle( Vec2f(50,50), 20 );
			//gl::draw( mFboScene.getTexture() );//TODO - screenshot?
		gl::popMatrices();
	mFboScene.unbindFramebuffer();

	// bind the blur shader
	mShaderBlur.bind();
	mShaderBlur.uniform("tex0", 0); // use texture unit 0
 
	// tell the shader to blur horizontally and the size of 1 pixel
	mShaderBlur.uniform("sampleOffset", Vec2f(1.0f/mFboBlur1.getWidth(), 0.0f));

	// copy a horizontally blurred version of our scene into the first blur Fbo
	
	gl::setViewport( mFboBlur1.getBounds() );
	mFboBlur1.bindFramebuffer();
		mFboScene.bindTexture(0);
		gl::pushMatrices();
			gl::setMatricesWindow( viewport.getWidth(), viewport.getHeight(), false );
			gl::clear( Color::black() );
			gl::drawSolidRect( mFboBlur1.getBounds() );
		gl::popMatrices();
		mFboScene.unbindTexture();
	mFboBlur1.unbindFramebuffer();

 
	// tell the shader to blur vertically and the size of 1 pixel
	mShaderBlur.uniform("sampleOffset", Vec2f(0.0f, 1.0f/mFboBlur2.getHeight()));

	// copy a vertically blurred version of our blurred scene into the second blur Fbo
	gl::setViewport( mFboBlur2.getBounds() );
	mFboBlur2.bindFramebuffer();
		mFboBlur1.bindTexture(0);
		gl::pushMatrices();
			gl::setMatricesWindow( viewport.getWidth(), viewport.getHeight(), false );
			gl::clear( Color::black() );
			gl::drawSolidRect( mFboBlur2.getBounds() );
		gl::popMatrices();
		mFboBlur1.unbindTexture();
	mFboBlur2.unbindFramebuffer();

	// unbind the shader
	mShaderBlur.unbind();

	// restore the viewport
	gl::setViewport( viewport );
	// because the Fbo's have their origin in the LOWER-left corner,
	// flip the Y-axis before drawing
	gl::pushModelView();
	gl::translate( Vec2f(0, 0 ) );// viewport.getHeight() ) );
	gl::scale( Vec3f(1, 1, 1) );

	// draw the 3 Fbo's 
	//gl::color( Color::white() );
	//gl::draw( mFboScene.getTexture(), Rectf(0, 0, 256, 256) );
	//gl::draw( mFboBlur1.getTexture(), Rectf(260, 0, 260 + 256, 256) );
	//gl::draw( mFboBlur2.getTexture(), Rectf(520, 0, 520 + 256, 256) );

	// draw our scene with the blurred version added as a blend
	gl::color( Color::white() );
	
	gl::enableAdditiveBlending();
	gl::draw( mFboScene.getTexture(), Rectf(0, 0, viewport.getWidth(), viewport.getHeight() ));

	gl::draw( mFboBlur2.getTexture(), Rectf(0, 0, viewport.getWidth(), viewport.getHeight() ));
	gl::disableAlphaBlending();

	// restore the modelview matrix
	gl::popModelView();

	if (flipScreen == true){
		gl::popMatrices();
	}
	
	gl::color( Color(1.0,1.0,1.0) );
	
	
	//These are for debug only
	//drawTitleSafeArea();
	//OutlineParams::getInstance()->draw();
}
void KinectEcard::draw()
{
	gl::clear( Color::black() );
	gl::color( Color::white() );

	//
	gl::setViewport( app::getWindowBounds() );

	// draw FBO's
	gl::pushMatrices();
	{
		// draw video stream and info string
		gl::pushMatrices();
			mVideoFbo.getTexture().setFlipped();
			gl::draw( mVideoFbo.getTexture() );

			gl::pushMatrices();
				gl::enableAlphaBlending();
				gl::drawString( "Video stream ", Vec2f( 20, 10 ), ColorA::black(), Font( "Arial", 40 )  );
				gl::disableAlphaBlending();
			gl::popMatrices();
		gl::popMatrices();

		gl::pushMatrices();
			gl::translate( mVideoFbo.getWidth(), 0 );
			mDepthFbo.getTexture().setFlipped();
			gl::draw( mDepthFbo.getTexture() );

				gl::pushMatrices();
					gl::enableAlphaBlending();
					gl::drawString( "Depth stream ", Vec2f( 20, 10 ), ColorA::black(), Font( "Arial", 40 )  );
					gl::disableAlphaBlending();
				gl::popMatrices();
			gl::popMatrices();
		gl::popMatrices();
		
		gl::pushMatrices();
			gl::translate( 0, mVideoFbo.getHeight() );
			gl::draw( mSubstractedVideoFbo.getTexture() );

			gl::pushMatrices();
				gl::enableAlphaBlending();
				gl::drawString( "Result ", Vec2f( 20, 10 ), ColorA::black(), Font( "Arial", 40 )  );
				gl::disableAlphaBlending();
			gl::popMatrices();
		gl::popMatrices();

		gl::pushMatrices();
			gl::translate( mVideoFbo.getWidth(), mVideoFbo.getHeight() );
			mStoredDepthFbo.getTexture().setFlipped();
			gl::draw( mStoredDepthFbo.getTexture() );

			gl::pushMatrices();
				gl::enableAlphaBlending();
				gl::drawString( "Stored depth buffer ", Vec2f( 20, 10 ), ColorA::black(), Font( "Arial", 40 )  );
				gl::disableAlphaBlending();
			gl::popMatrices();
		gl::popMatrices();

		if( mDrawDepthCorrectionMap ){
			gl::pushMatrices();
			{
				gl::scale( 0.25f, 0.25f );
				gl::draw( mCorrectionMap );
			}
			gl::popMatrices();
		}
	}
	gl::popMatrices();

	// draw bounderies for niceness
	gl::pushMatrices();
		gl::color( ColorA::black() );
		gl::drawLine( Vec3i( 0, mVideoFbo.getHeight(), 0 ), Vec3i( mVideoFbo.getWidth()*2, mVideoFbo.getHeight(), 0 ) );
		gl::drawLine( Vec3i( mVideoFbo.getWidth(), 0, 0 ), Vec3i( mVideoFbo.getWidth(), mVideoFbo.getHeight()*2, 0 ) );
	gl::popMatrices();

	mParams.draw();
}
Example #10
0
void Simulacra::blur()
{
    //    glEnable( GL_TEXTURE_2D );
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    Area viewport = gl::getViewport();

    // render a simple scene into mFboScene
    gl::setViewport( sceneFBO.getBounds() );
    sceneFBO.bindFramebuffer();
    //        gl::pushMatrices();
    //            gl::setMatricesWindow(FBO_WIDTH, FBO_HEIGHT, false);
    gl::clear( ColorA(0,0,0,0) );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    gl::pushMatrices();
    gl::setMatrices(camera);
    try{
        //Draw points
        synthMenu->drawTerrain();
        synthMenu->drawSynths();
    } catch(...) {
        std::cout << "drawing error!" << std::endl;
    }
    gl::popMatrices();
    sceneFBO.unbindFramebuffer();


    // bind the blur shader
    blurShader.bind();
    blurShader.uniform("tex0", 0); // use texture unit 0

    // tell the shader to blur horizontally and the size of 1 pixel
    blurShader.uniform("sampleOffset", Vec2f(1.0f/blurFBO1.getWidth(), 0.0f));

    //FIRST PASS
    // copy a horizontally blurred version of our scene into the first blur Fbo
    gl::setViewport( blurFBO1.getBounds() );
    blurFBO1.bindFramebuffer();
    sceneFBO.bindTexture(0);
    gl::pushMatrices();
    gl::setMatricesWindow(FBO_WIDTH, FBO_HEIGHT, false);
    gl::clear( ColorA(0,0,0,0) );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glColor4f(1,1,1,1);
    gl::drawSolidRect( blurFBO1.getBounds() );
    gl::popMatrices();
    sceneFBO.unbindTexture();
    blurFBO1.unbindFramebuffer();

    // tell the shader to blur vertically and the size of 1 pixel
    blurShader.uniform("sampleOffset", Vec2f(0.0f, 1.0f/blurFBO2.getHeight()));

    // copy a vertically blurred version of our blurred scene into the second blur Fbo
    gl::setViewport( blurFBO2.getBounds() );
    blurFBO2.bindFramebuffer();
    blurFBO1.bindTexture(0);
    gl::pushMatrices();
    gl::setMatricesWindow(FBO_WIDTH, FBO_HEIGHT, false);
    gl::clear( ColorA(0,0,0,0) );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glColor4f(1,1,1,1);
    gl::drawSolidRect( blurFBO2.getBounds() );
    gl::popMatrices();
    blurFBO1.unbindTexture();
    blurFBO2.unbindFramebuffer();

    //SECOND PASS
    // copy a horizontally blurred version of our scene into the first blur Fbo
    blurShader.uniform("sampleOffset", Vec2f(1.0f/blurFBO1.getWidth(), 0.0f));
    gl::setViewport( blurFBO1.getBounds() );
    blurFBO1.bindFramebuffer();
    blurFBO2.bindTexture(0);
    gl::pushMatrices();
    gl::setMatricesWindow(FBO_WIDTH, FBO_HEIGHT, false);
    gl::clear( ColorA(0,0,0,0) );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glColor4f(1,1,1,1);
    gl::drawSolidRect( blurFBO1.getBounds() );
    gl::popMatrices();
    blurFBO2.unbindTexture();
    blurFBO1.unbindFramebuffer();

    // tell the shader to blur vertically and the size of 1 pixel
    blurShader.uniform("sampleOffset", Vec2f(0.0f, 1.0f/blurFBO2.getHeight()));

    // copy a vertically blurred version of our blurred scene into the second blur Fbo
    gl::setViewport( blurFBO2.getBounds() );
    blurFBO2.bindFramebuffer();
    blurFBO1.bindTexture(0);
    gl::pushMatrices();
    gl::setMatricesWindow(FBO_WIDTH, FBO_HEIGHT, false);
    gl::clear( ColorA(0,0,0,0) );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glColor4f(1,1,1,1);
    gl::drawSolidRect( blurFBO2.getBounds() );
    gl::popMatrices();
    blurFBO1.unbindTexture();
    blurFBO2.unbindFramebuffer();

    if(section == 1)
    {
        //SECOND PASS
        // copy a horizontally blurred version of our scene into the first blur Fbo
        blurShader.uniform("sampleOffset", Vec2f(3.0f/blurFBO1.getWidth(), 0.0f));
        gl::setViewport( blurFBO1.getBounds() );
        blurFBO1.bindFramebuffer();
        blurFBO2.bindTexture(0);
        gl::pushMatrices();
        gl::setMatricesWindow(FBO_WIDTH, FBO_HEIGHT, false);
        gl::clear( ColorA(0,0,0,0) );
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
        glColor4f(1,1,1,1);
        gl::drawSolidRect( blurFBO1.getBounds() );
        gl::popMatrices();
        blurFBO2.unbindTexture();
        blurFBO1.unbindFramebuffer();

        // tell the shader to blur vertically and the size of 1 pixel
        blurShader.uniform("sampleOffset", Vec2f(0.0f, 3.0f/blurFBO2.getHeight()));

        // copy a vertically blurred version of our blurred scene into the second blur Fbo
        gl::setViewport( blurFBO2.getBounds() );
        blurFBO2.bindFramebuffer();
        blurFBO1.bindTexture(0);
        gl::pushMatrices();
        gl::setMatricesWindow(FBO_WIDTH, FBO_HEIGHT, false);
        gl::clear( ColorA(0,0,0,0) );
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
        glColor4f(1,1,1,1);
        gl::drawSolidRect( blurFBO2.getBounds() );
        gl::popMatrices();
        blurFBO1.unbindTexture();
        blurFBO2.unbindFramebuffer();
    }

    // unbind the shader
    blurShader.unbind();

    //gl::translate(0,0,250);

    gl::setViewport( viewport );
    glEnable(GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA,GL_ONE);
    // draw our scene with the blurred version added as a blend
    glColor4f(1,1,1,1);
    //

    gl::enableAlphaBlending(true);

    if(section==1)
    {
        finalFBO.bindFramebuffer();
    }
    gl::clear(ColorA(0,0,0,1));
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    if(section!=1)
    {
        gl::pushMatrices();
        gl::setMatrices(camera);
        synthMenu->drawTerrain();
        synthMenu->drawSynths();
        gl::popMatrices();

    }
    gl::enableAdditiveBlending();

    if(section == 1 || section == 2 || section == 3)
    {
        //        gl::enableAlphaBlending(true);
        gl::draw( blurFBO2.getTexture(), getWindowBounds() );
        gl::draw( blurFBO2.getTexture(), getWindowBounds() );
        gl::draw( blurFBO2.getTexture(), getWindowBounds() );
        gl::draw( blurFBO2.getTexture(), getWindowBounds() );
    }
    gl::draw( blurFBO2.getTexture(), getWindowBounds() );

    gl::disableAlphaBlending();
    if(section==1)
    {
        finalFBO.unbindFramebuffer();
    }
}
Example #11
0
void FolApp::setup()
{
    gl::disableVerticalSync();

    mParams = params::InterfaceGl( "Parameters", Vec2i( 200, 300 ) );
    mParams.addParam( "Blur amount", &mBlurAmount, "min=0 max=128 step=1" );
    mParams.addParam( "Clip", &mClip, "min=0 max=1 step=.005" );
    mParams.addParam( "Step", &mStep, "min=1 max=128 step=.5" );
    mParams.addSeparator();
    mParams.addParam( "Fps", &mFps, "", true );

    mParams.addSeparator();
    mParams.addButton( "Start recording", std::bind(&FolApp::toggleRecording, this ));

    mBlurKernelTexture = loadImage( loadResource( RES_BLUR_KERNEL ) );
    mBlurShader = gl::GlslProg( loadResource( RES_PASSTHROUGH_VERT ),
                                loadResource( RES_BLUR_FRAG ) );
    mWaveShader = gl::GlslProg( loadResource( RES_WAVE_VERT ),
                                loadResource( RES_WAVE_FRAG ) );

    gl::Fbo::Format format;
    format.enableColorBuffer( true, 2 );
    format.enableDepthBuffer( false );
    mDepthFbo = gl::Fbo( 640, 480, format );

    format.enableColorBuffer( true, 8 );
    format.enableDepthBuffer( false );
    format.setWrap( GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE );
    mOutputFbo = gl::Fbo( mDepthFbo.getWidth(),
                          mDepthFbo.getHeight(), format );
    mBloomFbo = gl::Fbo( mDepthFbo.getWidth() / 4,
                         mDepthFbo.getHeight() / 4, format );

    mBloomShader = gl::GlslProg( loadResource( RES_KAWASE_BLOOM_VERT ),
                                 loadResource( RES_KAWASE_BLOOM_FRAG ) );
    mBloomShader.bind();
    mBloomShader.uniform( "tex", 0 );
    mBloomShader.uniform( "pixelSize", Vec2f( 1. / mBloomFbo.getWidth(), 1. / mBloomFbo.getHeight() ) );
    mBloomShader.unbind();


    mMixerShader = gl::GlslProg( loadResource( RES_PASSTHROUGH_VERT ),
                                 loadResource( RES_MIXER_FRAG ) );
    mMixerShader.bind();
    int texUnits[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
    mMixerShader.uniform("tex", texUnits, 9);
    mMixerShader.unbind();

    /*
    	 0 0, 0, 0
    	 1 0.00392157, 0, 0
    	 2 0.0352941, 0.0235294, 0
    	 3 0.0745098, 0.0627451, 0
    	 4 0.117647, 0.12549, 0
    	 5 0.172549, 0.239216, 0
    	 6 0.227451, 0.388235, 0
    	 7 0.278431, 0.533333, 0
    	 8 0.345098, 0.717647, 0
    	 9 0.407843, 0.898039, 0
    	10 0.466667, 0.980392, 0
    	11 0.529412, 0.898039, 0
    	12 0.6, 0.717647, 0
    	13 0.662745, 0.533333, 0
    	14 0.721569, 0.388235, 0
    	15 0.780392, 0.243137, 0
    	16 0.835294, 0.129412, 0
    	17 0.882353, 0.0627451, 0
    	18 0.933333, 0.0235294, 0
    	19 0.980392, 0, 0
    	20 1, 0, 0
     */

    createVbo();

    // start OpenNI
    try
    {
        //mNI = OpenNI( OpenNI::Device() );

        //*
        string path = getAppPath().string();
#ifdef CINDER_MAC
        path += "/../";
#endif
        path += "rec-12033015082700.oni";
        mNI = OpenNI( path );
        //*/
    }
    catch (...)
    {
        console() << "Could not open Kinect" << endl;
        quit();
    }

    mNI.setMirrored( true );
    mNI.start();
}
Example #12
0
void FolApp::draw()
{
    gl::clear( Color::black() );

    if ( !mDepthTexture )
        return;

    // blur depth
    mDepthFbo.bindFramebuffer();
    gl::setMatricesWindow( mDepthFbo.getSize(), false );
    gl::setViewport( mDepthFbo.getBounds() );

    mBlurShader.bind();

    mBlurShader.uniform( "kernelSize", (float)mBlurKernelTexture.getWidth() );
    mBlurShader.uniform( "invKernelSize", 1.f / mBlurKernelTexture.getWidth() );
    mBlurShader.uniform( "imageTex", 0 );
    mBlurShader.uniform( "kernelTex", 1 );
    mBlurShader.uniform( "blurAmount", mBlurAmount );

    // pass 1
    glDrawBuffer( GL_COLOR_ATTACHMENT0_EXT );

    //gl::enable( GL_TEXTURE_2D );
    mDepthTexture.bind( 0 );
    mBlurKernelTexture.bind( 1 );
    mBlurShader.uniform( "stepVector", Vec2f( 1. / mDepthTexture.getWidth(), 0. ) );

    gl::drawSolidRect( mDepthFbo.getBounds() );

    mDepthTexture.unbind();

    // pass 2
    glDrawBuffer( GL_COLOR_ATTACHMENT1_EXT );

    mDepthFbo.bindTexture( 0 );
    mBlurShader.uniform( "stepVector", Vec2f( 0., 1. / mDepthFbo.getHeight() ) );
    gl::drawSolidRect( mDepthFbo.getBounds() );

    mDepthFbo.unbindTexture();
    mBlurKernelTexture.unbind();
    mBlurShader.unbind();

    mDepthFbo.unbindFramebuffer();

    // wave output
    mOutputFbo.bindFramebuffer();
    gl::setMatricesWindow( mOutputFbo.getSize(), false );
    gl::setViewport( mOutputFbo.getBounds() );

    gl::clear( Color::black() );
    gl::disableDepthRead();
    gl::disableDepthWrite();

    gl::enableAdditiveBlending();
    gl::color( ColorA( 1, 1, 1, .0195 ) );

    gl::pushMatrices();
    gl::scale( Vec2f( getWindowWidth() / (float)VBO_X_SIZE,
                      getWindowHeight() / (float)VBO_Y_SIZE) );

    mDepthFbo.getTexture( 1 ).bind();
    mWaveShader.bind();
    mWaveShader.uniform( "tex", 0 );
    mWaveShader.uniform( "invSize", Vec2f( mStep / mDepthFbo.getWidth(),
                                           mStep / mDepthFbo.getHeight() ) );
    mWaveShader.uniform( "clip", mClip );
    gl::draw( mVboMesh );
    mWaveShader.unbind();

    gl::popMatrices();

    gl::disableAlphaBlending();
    mOutputFbo.unbindFramebuffer();

    // bloom
    mBloomFbo.bindFramebuffer();

    gl::setMatricesWindow( mBloomFbo.getSize(), false );
    gl::setViewport( mBloomFbo.getBounds() );

    gl::color( Color::white() );
    mOutputFbo.getTexture().bind();

    mBloomShader.bind();
    for (int i = 0; i < 8; i++)
    {
        glDrawBuffer( GL_COLOR_ATTACHMENT0_EXT + i );
        mBloomShader.uniform( "iteration", i );
        gl::drawSolidRect( mBloomFbo.getBounds() );
        mBloomFbo.bindTexture( 0, i );
    }
    mBloomShader.unbind();

    glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
    mBloomFbo.unbindFramebuffer();

    // output mixer
    gl::setMatricesWindow( getWindowSize() );
    gl::setViewport( getWindowBounds() );

    mMixerShader.bind();

    gl::enable( GL_TEXTURE_2D );

    mOutputFbo.getTexture().bind( 0 );
    for (int i = 0; i < 8; i++)
    {
        mBloomFbo.getTexture( i ).bind( i + 1 );
    }

    gl::drawSolidRect( mOutputFbo.getBounds() );
    gl::disable( GL_TEXTURE_2D );
    mMixerShader.unbind();

    //gl::draw( mOutputFbo.getTexture(), getWindowBounds() );
    //gl::draw( mDepthFbo.getTexture( 1 ), getWindowBounds() );

    params::InterfaceGl::draw();
}