Esempio n. 1
0
void Simulacra::helix()
{
    glDisable(GL_LIGHTING);
    glDisable(GL_LIGHT0);

    // render a simple scene into mFboScene
    helixShader.bind();
    gl::translate(0,0,0);
    helixFBO.bindFramebuffer();

    helixShader.uniform("time",Vec2f(sin(rotation),1-sin(rotation*0.71)));
    gl::clear(ColorA(0,0,0,1));
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    gl::drawSolidRect(cinder::Rectf(0,0,getWindowWidth(),getWindowHeight()));
    helixFBO.unbindFramebuffer();
    helixShader.unbind();

    //Revert back to screen
    gl::color(cinder::ColorA(1,1,1,1));
    applyHelixShader.bind();
    finalFBO.bindTexture(0);
    applyHelixShader.uniform("qt_Texture0",0);
    helixFBO.bindTexture(1);
    applyHelixShader.uniform("qt_Texture1",1);

    gl::drawSolidRect(cinder::Rectf(0,getWindowHeight(),getWindowWidth(),0));
    applyHelixShader.unbind();
    helixFBO.unbindTexture();
    finalFBO.unbindTexture();

    gl::color(ColorA(1,1,1,1));
}
Esempio n. 2
0
void FBOBasicApp::draw()
{
	// clear the window to gray
	gl::clear( Color( 0.35f, 0.35f, 0.35f ) );

	// setup our camera to render the cube
	CameraPersp cam( getWindowWidth(), getWindowHeight(), 60.0f );
	cam.setPerspective( 60, getWindowAspectRatio(), 1, 1000 );
	cam.lookAt( Vec3f( 2.6f, 1.6f, -2.6f ), Vec3f::zero() );
	gl::setMatrices( cam );

	// set the viewport to match our window
	gl::setViewport( getWindowBounds() );

	// use the scene we rendered into the FBO as a texture
	glEnable( GL_TEXTURE_2D );
	mFbo.bindTexture();

	// draw a cube textured with the FBO
	gl::color( Color::white() );
	gl::drawCube( Vec3f::zero(), Vec3f( 2.2f, 2.2f, 2.2f ) );

	// show the FBO texture in the upper left corner
	gl::setMatricesWindow( getWindowSize() );
	gl::draw( mFbo.getTexture(0), Rectf( 0, 0, 96, 96 ) );
	
#if ! defined( CINDER_GLES ) // OpenGL ES can't do depth textures, otherwise draw the FBO's
	gl::draw( mFbo.getDepthTexture(), Rectf( 96, 0, 96 + 96, 96 ) );
#endif
}
void	KinectEcard::snapshot(){
	gl::Fbo fbo( 640, 480, false );

	// render stored depth FBO
	fbo.bindFramebuffer();
	gl::pushMatrices();
		gl::clear( Color::black() );
		gl::color( Color::white() );
		gl::setMatricesWindowPersp( fbo.getSize() );

		mDepthCompareShader.bind();

		mDepthCompareShader.uniform( "tex0", 0 );
		mDepthCompareShader.uniform( "tex1", 1 );

		mDepthFbo.bindTexture(0);
		mStoredDepthFbo.bindTexture(1);

		gl::translate( 0, 480 );
		gl::scale( 1, -1 );

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

		mDepthCompareShader.unbind();
	gl::popMatrices();
	fbo.unbindFramebuffer();

	// save stored depth fbo
	fbo.blitTo( mStoredDepthFbo, fbo.getBounds(), mStoredDepthFbo.getBounds() );

	// render substracted video fbo
	fbo.bindFramebuffer();
	gl::pushMatrices();
		gl::clear( Color::black() );
		gl::color( Color::white() );
		gl::setMatricesWindowPersp( mSubstractedVideoFbo.getSize() );
		gl::draw( mSubstractedVideoFbo.getTexture() );
	gl::popMatrices();
	fbo.unbindFramebuffer();

	// save it
	fbo.blitTo( mStoredVideoFbo, fbo.getBounds(), mStoredVideoFbo.getBounds() );
}
void HiKinectApp::draw3D() {
	
	gl::setMatrices( mCamUI.getCamera() );
	if (mWireframe) gl::enableWireframe();
	else gl::disableWireframe();
	
	if (mLighting) {
		glEnable( GL_LIGHTING );
		glEnable( GL_LIGHT0 );
	}
//	GLfloat light_position[] = { mMousePos.x, mMousePos.y, -275.0f, 0.0f };
	GLfloat light_position[] = { 0, 0, 1.0f, 0.0f };
	glLightfv( GL_LIGHT0, GL_POSITION, light_position );
	if( DIFFUSE ){
		ci::ColorA color( CM_RGB, 1.0f, 1.0f, 1.0f, 1.0f );
		glMaterialfv( GL_FRONT, GL_DIFFUSE,	color );
	} else {
		glMaterialfv( GL_FRONT, GL_DIFFUSE,	no_mat );
	}
	
	if( AMBIENT )
		glMaterialfv( GL_FRONT, GL_AMBIENT,	mat_ambient );
	else
		glMaterialfv( GL_FRONT, GL_AMBIENT,	no_mat );
	
	if( SPECULAR ){
		glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular );
		glMaterialfv( GL_FRONT, GL_SHININESS, mat_shininess );
	} else {
		glMaterialfv( GL_FRONT, GL_SPECULAR, no_mat );
		glMaterialfv( GL_FRONT, GL_SHININESS, no_shininess );
	}
	
	if( EMISSIVE )
		glMaterialfv( GL_FRONT, GL_EMISSION, mat_emission );
	else
		glMaterialfv( GL_FRONT, GL_EMISSION, no_mat );
	
	if (mDepthTexture)
		mDepthTexture.bind(0);
	mFbo.bindTexture(1);
	if (mColorTexture)
		mColorTexture.bind(2);
	
	mGridMesh.draw( lmap(mMousePos.x, 0.0f, (float)getWindowWidth(), 0.0f, 1.0f) );
	
	if (mLighting) {
		glDisable( GL_LIGHTING );
		glDisable( GL_LIGHT0 );
	}
	
	gl::disableWireframe();
}
void KinectEcard::renderSubstractedVideo(){
	mSubstractedVideoFbo.bindFramebuffer();

	gl::pushMatrices();
	{
		// clear FBO
		gl::clear( Color::black() );
		gl::color( Color::white() );

		//
		gl::setMatricesWindowPersp( mSubstractedVideoFbo.getSize() );

		mSubstractShader.bind();
		mSubstractShader.uniform( "tex0", 0 );
		mSubstractShader.uniform( "tex1", 1 );
		mSubstractShader.uniform( "tex2", 2 );
		mSubstractShader.uniform( "tex3", 3 );

		mVideoFbo.bindTexture(0);
		mDepthFbo.bindTexture(1);
		mStoredVideoFbo.bindTexture(2);
		mStoredDepthFbo.bindTexture(3);
		
		gl::drawSolidRect( mSubstractedVideoFbo.getBounds() );

		mVideoFbo.unbindTexture();
		mDepthFbo.unbindTexture();
		mStoredVideoFbo.unbindTexture();
		mStoredDepthFbo.unbindTexture();

		mSubstractShader.unbind();
	}
	gl::popMatrices();

	mSubstractedVideoFbo.unbindFramebuffer();
}
Esempio n. 6
0
void RepulsionApp::draw()
{
	// clear out the window with black
	gl::clear( ColorA( 0.1f, 0.1f, 0.1f, 0.0f ), true );
	
	gl::setMatricesWindow( getWindowSize(), false );
	gl::setViewport( getWindowBounds() );

	gl::disableDepthRead();
	gl::disableDepthWrite();
	gl::enable( GL_TEXTURE_2D );
	gl::enableAlphaBlending();
	
	gl::color( ColorA( 1.0f, 1.0f, 1.0f, 1.0f ) );
	
	// DRAW ROOM
	mRoomFbo.bindTexture();
	gl::drawSolidRect( getWindowBounds() );
	
	gl::setMatrices( mSpringCam.getCam() );
	
	// DRAW PANEL
	drawInfoPanel();
	gl::enable( GL_TEXTURE_2D );
	
	gl::enableDepthRead();
	gl::enableDepthWrite();
	
	// DRAW PARTICLES
	mPositionFbos[mThisFbo].bindTexture( 0 );
	mVelocityFbos[mThisFbo].bindTexture( 1 );
	mShader.bind();
	mShader.uniform( "currentPosition", 0 );
	mShader.uniform( "currentVelocity", 1 );
	mShader.uniform( "eyePos", mSpringCam.getEye() );
	mShader.uniform( "power", mRoom.getPower() );
	gl::draw( mSphereVbo );
	mShader.unbind();
	
	if( mSaveFrames && mNumSavedFrames < 15000 ){
		writeImage( *getHomeDirectory().c_str() + "RepulsionGPU/" + toString( mNumSavedFrames ) + ".png", copyWindowSurface() );
		mNumSavedFrames ++;
	}
	
	mThisFbo	= ( mThisFbo + 1 ) % 2;
	mPrevFbo	= ( mThisFbo + 1 ) % 2;
}
Esempio n. 7
0
void TerrainApp::draw()
{
	float power = mRoom.getPower();
	
	gl::clear( ColorA( 0.1f, 0.1f, 0.1f, 0.0f ), true );
	
	gl::setMatricesWindow( getWindowSize(), false );
	gl::setViewport( getWindowBounds() );

	gl::disableDepthRead();
	gl::disableDepthWrite();
	gl::enableAlphaBlending();
	gl::enable( GL_TEXTURE_2D );
	gl::color( ColorA( 1.0f, 1.0f, 1.0f, 1.0f ) );
	
	// DRAW ROOM FBO
	mRoomFbo.bindTexture();
	gl::drawSolidRect( getWindowBounds() );
	
	gl::setMatrices( mSpringCam.getCam() );
	gl::color( ColorA( power, power, power, power * 0.1f + 0.9f ) );
	
	// DRAW INFO PANEL
	drawInfoPanel();
	
	gl::enable( GL_TEXTURE_2D );
	gl::color( ColorA( 1.0f, 1.0f, 1.0f, 1.0f ) );
	
	// DRAW WALLS
	mRoom.drawWalls( mRoom.getPower(), mRoomBackWallTex, mRoomLeftWallTex, mRoomRightWallTex, mRoomCeilingTex, mRoomFloorTex, mRoomBlankTex );
	
	gl::enableAlphaBlending();
	gl::enableDepthRead();
	gl::enableDepthWrite();
	gl::enable( GL_TEXTURE_2D );
	
	// DRAW TERRAIN
	drawTerrain();
	
	gl::disable( GL_TEXTURE_2D );
	
	// DRAW SPHERE
	drawSphere();
}
Esempio n. 8
0
void Grove::copyBlur(gl::Fbo& source, gl::Fbo& target, Vec2f sampleOffset)
{
	// bind the blur shader
	mBlurShader.bind();
	mBlurShader.uniform("tex0", 0); // use texture unit 0
	mBlurShader.uniform("sampleOffset", sampleOffset);

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

	// unbind the shader
	mBlurShader.unbind();
}
Esempio n. 9
0
void ShadedSphereApp::draw()
{
	gl::clear( ColorA( 0, 0, 0, 0 ), true );
	gl::color( ColorA( 1, 1, 1, 1 ) );
	
	gl::setMatricesWindow( getWindowSize(), false );
	gl::setViewport( getWindowBounds() );

	gl::disableDepthRead();
	gl::disableDepthWrite();
	gl::enableAlphaBlending();
	gl::enable( GL_TEXTURE_2D );
	
	// DRAW ROOM
	mRoomFbo.bindTexture();
	gl::drawSolidRect( getWindowBounds() );
	
	gl::setMatrices( mSpringCam.getCam() );
	gl::enableDepthRead();
	gl::enableDepthWrite();
	
	drawSphere();
}
void BubbleChamberApp::drawGuts(Area area)
{
	float power = mRoom.getPower();
	Color powerColor = Color( power, power, power );
	
	drawIntoRoomFbo();
	
	gl::setMatricesWindow( getWindowSize(), false );
	//gl::setViewport( getWindowBounds() );
	gl::setViewport( area );

	gl::disableDepthRead();
	gl::disableDepthWrite();
	gl::enableAlphaBlending();
	gl::enable( GL_TEXTURE_2D );
	gl::color( ColorA( 1.0f, 1.0f, 1.0f, 1.0f ) );
	
	// ROOM
	mRoomFbo.bindTexture();
	gl::drawSolidRect( getWindowBounds() );
	
	
	//mActiveCam.setFixedPipeline();
	// PANEL
	drawInfoPanel();

	gl::pushMatrices();
	gl::setMatrices( mActiveCam.getCam() );

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity(); // zero it out
	glMultMatrixf(mActiveCam.mProjectionMatrix); // Apply the matrix to the loaded projection matrix
	glMatrixMode(GL_MODELVIEW); // Return to our modelview matrix
	
	gl::disable( GL_TEXTURE_2D );
	gl::enableDepthWrite();
	gl::enableDepthRead();
	gl::enableAlphaBlending();
	gl::color( ColorA( powerColor, 1.0f ) );
	
	// PARTICLES
	mController.drawParticles( power );
	
	// DRAW GIBS
	mController.drawGibs();
	
	// BUBBLES
	mController.drawBubbles( power );
	
	gl::enable( GL_TEXTURE_2D );
	gl::disableDepthWrite();
	
	// DECALS
	gl::color( powerColor );
	mDecalTex.bind( 0 );
	mController.drawDecals();
	
	// SMOKES
	Vec3f right, up;
	mActiveCam.getCam().getBillboardVectors( &right, &up );
	mSmokeTex.bind( 0 );
	mController.drawSmokes( right, up );

	gl::disable( GL_TEXTURE_2D );
	gl::enableDepthWrite();
	gl::color( powerColor );
	
	// MOTHS
	mController.drawMoths();
	
	// GLOWCUBES
	mGlowCubeShader.bind();
	mGlowCubeShader.uniform( "eyePos", mActiveCam.getEye() );
	mGlowCubeShader.uniform( "power", mRoom.getPower() );
	mGlowCubeShader.uniform( "mvpMatrix", mActiveCam.mMvpMatrix );
	mController.drawGlowCubes( &mGlowCubeShader );
	mGlowCubeShader.unbind();

	if( mSaveFrames ){
//		writeImage( getHomeDirectory() + "BubbleChamber/" + toString( mNumSaveFrames ) + ".png", copyWindowSurface() );
		mNumSaveFrames ++;
	}
	
	gl::popMatrices();
}
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();
}
Esempio n. 12
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();
}
Esempio n. 13
0
void BubbleChamberApp::draw()
{
	float power = mRoom.getPower();
	Color powerColor = Color( power, power, power );
	
	gl::clear( ColorA( 0.1f, 0.1f, 0.1f, 0.0f ), true );
	
	gl::setMatricesWindow( getWindowSize(), false );
	gl::setViewport( getWindowBounds() );

	gl::disableDepthRead();
	gl::disableDepthWrite();
	gl::enableAlphaBlending();
	gl::enable( GL_TEXTURE_2D );
	gl::color( ColorA( 1.0f, 1.0f, 1.0f, 1.0f ) );
	
	// ROOM
	mRoomFbo.bindTexture();
	gl::drawSolidRect( getWindowBounds() );
	
	gl::setMatrices( mSpringCam.getCam() );
	
	// PANEL
	drawInfoPanel();
	
	gl::disable( GL_TEXTURE_2D );
	gl::enableDepthWrite();
	gl::enableDepthRead();
	gl::enableAlphaBlending();
	gl::color( ColorA( powerColor, 1.0f ) );
	
	// PARTICLES
	mController.drawParticles( power );
	
	// DRAW GIBS
	mController.drawGibs();
	
	// BUBBLES
	mController.drawBubbles( power );
	
	gl::enable( GL_TEXTURE_2D );
	gl::disableDepthWrite();
	
	// DECALS
	gl::color( powerColor );
	mDecalTex.bind( 0 );
	mController.drawDecals();
	
	// SMOKES
	Vec3f right, up;
	mSpringCam.getCam().getBillboardVectors( &right, &up );
	mSmokeTex.bind( 0 );
	mController.drawSmokes( right, up );

	gl::disable( GL_TEXTURE_2D );
	gl::enableDepthWrite();
	gl::color( powerColor );
	
	// MOTHS
	mController.drawMoths();
	
	// GLOWCUBES
	mGlowCubeShader.bind();
	mGlowCubeShader.uniform( "eyePos", mSpringCam.getEye() );
	mGlowCubeShader.uniform( "power", mRoom.getPower() );
	mGlowCubeShader.uniform( "mvpMatrix", mSpringCam.mMvpMatrix );
	mController.drawGlowCubes( &mGlowCubeShader );
	mGlowCubeShader.unbind();

	if( mSaveFrames ){
		writeImage( *getHomeDirectory().c_str() + "BubbleChamber/" + toString( mNumSaveFrames ) + ".png", copyWindowSurface() );
		mNumSaveFrames ++;
	}
}
Esempio n. 14
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();
    }
}
Esempio n. 15
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();
}