예제 #1
0
void RepulsionApp::drawIntoPositionFbo()
{	
	gl::setMatricesWindow( mFboSize, false );
	gl::setViewport( mFboBounds );
	
	mPositionFbos[ mThisFbo ].bindFramebuffer();
	mPositionFbos[ mPrevFbo ].bindTexture( 0, 0 );
	mPositionFbos[ mPrevFbo ].bindTexture( 1, 1 );
	mVelocityFbos[ mThisFbo ].bindTexture( 2, 0 );
	mVelocityFbos[ mThisFbo ].bindTexture( 3, 1 );	
	mPositionShader.bind();
	mPositionShader.uniform( "pos0Tex", 0 );
	mPositionShader.uniform( "pos1Tex", 1 );
	mPositionShader.uniform( "vel0Tex", 2 );
	mPositionShader.uniform( "vel1Tex", 3 );
	mPositionShader.uniform( "dt", mRoom.getTimeDelta() );
	gl::drawSolidRect( mFboBounds );
	mPositionShader.unbind();
	
	mPositionFbos[ mThisFbo ].unbindFramebuffer();
}
예제 #2
0
void gpuPSApp::update()
{
    if (mStep) {
        computeAttractorPosition();
        
        gl::setMatricesWindow( mSwapFbo.getSize(), false ); // false to prevent vertical flipping
        gl::setViewport( mSwapFbo.getBounds() );
        
        mSwapFbo.updateBind();
        
        mParticlesShader.bind();
        mParticlesShader.uniform( "positions", 0 );
        mParticlesShader.uniform( "velocities", 1 );
        mParticlesShader.uniform( "attractorPos", mAttractor);
        gl::drawSolidRect(mSwapFbo.getBounds());
        mParticlesShader.unbind();
        
        mSwapFbo.updateUnbind();
        mSwapFbo.swap();
    }
}
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 SmoothDisplacementMappingApp::renderNormalMap()
{
	if( mNormalMapShader && mNormalMapFbo ) 
	{
		mNormalMapFbo.bindFramebuffer();
		{
			// setup viewport and matrices 
			glPushAttrib( GL_VIEWPORT_BIT );
			gl::setViewport( mNormalMapFbo.getBounds() );

			gl::pushMatrices();
			gl::setMatricesWindow( mNormalMapFbo.getSize(), false );

			// clear the color buffer
			gl::clear();			

			// bind the displacement map
			mDispMapFbo.getTexture().bind(0);

			// render the normal map
			mNormalMapShader.bind();
			mNormalMapShader.uniform( "texture", 0 );
			mNormalMapShader.uniform( "amplitude", 4.0f );

			Area bounds = mNormalMapFbo.getBounds(); //bounds.expand(-1, -1);
			gl::drawSolidRect( bounds );

			mNormalMapShader.unbind();

			// clean up after ourselves
			mDispMapFbo.getTexture().unbind();

			gl::popMatrices();

			glPopAttrib();
		}
		mNormalMapFbo.unbindFramebuffer();
	}
}
예제 #5
0
파일: gpuPSApp.cpp 프로젝트: flcc/gpuPS
void gpuPSApp::draw()
{
	gl::setMatrices( mCam );
	gl::setViewport( getWindowBounds() );
	gl::clear( ColorA( 0.0f, 0.0f, 0.0f, 1.0f ) );
	
	mFBO[mCurrentFBO].bindTexture(0,0);
	mDisplShader.bind();
	mDisplShader.uniform("displacementMap", 0 );
	gl::pushModelView();
	gl::translate( Vec3f( 0.0f, 0.0f, getWindowHeight() / 2.0f ) );
	gl::rotate( mArcball.getQuat() );
	gl::draw( mVboMesh );
    gl::popModelView();
	
	mDisplShader.unbind();
	mFBO[mCurrentFBO].unbindTexture();
	
	gl::setMatricesWindow(getWindowSize());
	gl::drawString( toString( SIDE*SIDE ) + " vertices", Vec2f(32.0f, 32.0f));
	gl::drawString( toString((int) getAverageFps()) + " fps", Vec2f(32.0f, 52.0f));
}
void ___PACKAGENAMEASIDENTIFIER___App::draw()
{
	// clear out the window with black
	gl::clear( kClearColor ); 
	
	if( !mTexture ) return;
	mFbo.bindFramebuffer();
	mTexture.enableAndBind();
	mShader.bind();
	mShader.uniform( "tex", 0 );
	mShader.uniform( "mixColor", Vec3d( mMixColorRed, mMixColorGreen, mMixColorBlue ) );
	gl::drawSolidRect( getWindowBounds() );
	mTexture.unbind();
	mShader.unbind();
	mFbo.unbindFramebuffer();
	
	gl::Texture fboTexture = mFbo.getTexture();
	fboTexture.setFlipped();
	gl::draw( fboTexture );

	params::InterfaceGl::draw();
}
예제 #7
0
void RDiffusionApp::update()
{	
	const int ITERATIONS = 25;
	// normally setMatricesWindow flips the projection vertically so that the upper left corner is 0,0
	// but we don't want to do that when we are rendering the FBOs onto each other, so the last param is false
	gl::setMatricesWindow( mFBOs[0].getSize(), false );
	gl::setViewport( mFBOs[0].getBounds() );
	for( int i = 0; i < ITERATIONS; i++ ) {
		mCurrentFBO = ( mCurrentFBO + 1 ) % 2;
		mOtherFBO   = ( mCurrentFBO + 1 ) % 2;
		
		mFBOs[ mCurrentFBO ].bindFramebuffer();
		mFBOs[ mOtherFBO ].bindTexture();
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
	  
		mShader.bind();
		mShader.uniform( "texture", 0 );
		mShader.uniform( "srcTexture", 1 );
		mShader.uniform( "width", (float)FBO_WIDTH );
		mShader.uniform( "ru", mReactionU );
		mShader.uniform( "rv", mReactionV );
		mShader.uniform( "k", mReactionK );
		mShader.uniform( "f", mReactionF );
		
		gl::drawSolidRect( mFBOs[ mCurrentFBO ].getBounds() );
		
		mShader.unbind();
		if( mMousePressed ){
			glColor3f( 1.0f, 1.0f, 1.0f );
			RectMapping windowToFBO( getWindowBounds(), mFBOs[mCurrentFBO].getBounds() );
			gl::drawSolidCircle( windowToFBO.map( mMouse ), 50.0f, 32 );
		}

		mFBOs[ mCurrentFBO ].unbindFramebuffer();
	}
}
예제 #8
0
void KinectEcard::renderVideo(){
	if( !mVideoSurface )
		return;

	gl::pushMatrices();
	{
		//
		mVideoFbo.bindFramebuffer();

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

		// 
		gl::Texture tex0( mVideoSurface );
		gl::Texture tex1( mCorrectionMap );

		mDepthCorrectionShader.bind();
		mDepthCorrectionShader.uniform( "tex0", 0 );
		mDepthCorrectionShader.uniform( "tex1", 1 );

		tex0.bind(0);
		tex1.bind(1);

		gl::setMatricesWindowPersp( mVideoFbo.getSize() );

		// draw video surface
		gl::drawSolidRect( mVideoFbo.getBounds() );
		//gl::draw( mCorrectionMap );

		mDepthCorrectionShader.unbind();

		mVideoFbo.unbindFramebuffer();
	}
	gl::popMatrices();
	
}
예제 #9
0
void SimpleExampleApp::draw()
{
	gl::setMatrices( mCam );

	gl::clear( Color( 0, 0, 0 ) ); 

	gl::disableAlphaBlending();	
	if( mTriMesh.getNumTriangles() ) {
		gl::pushMatrices();

		mShader.bind();
		mShader.uniform( "eyeDir", mCam.getViewDirection().normalized() );
		gl::draw( mTriMesh );
		mShader.unbind();

		gl::popMatrices();
	}
	
	gl::enableAlphaBlending();

	// Simple FPS display
	gl::setMatricesWindow( getWindowSize() );
	gl::drawString( toString( getAverageFps() ) + " fps", Vec2i( 5, 5 ), ColorA( 1, 1, 1, 0.5f ), Font( "Arial", 18 ) );
}
예제 #10
0
void KaleidoscopeApp::draw()
{
    gl::clear();

    gl::setViewport( getWindowBounds() );
    gl::setMatricesWindow( getWindowSize() );

    if ( mShader )
    {
        mShader.bind();
        mShader.uniform( "center", mCenter );
        mShader.uniform( "numReflectionLines", mNumReflectionLines );
        mShader.uniform( "rotation", mRotation );
        mShader.uniform( "txt", 0 );
    }

    if ( mTexture )
        gl::draw( mTexture, getWindowBounds() );

    if ( mShader )
        mShader.unbind();

    mParams.draw();
}
예제 #11
0
void TextRenderingApp::draw()
{
	// note: when drawing text to an FBO, 
	//  make sure to enable maximum quality multisampling (16x is best)!

	// clear out the window
	gl::clear( mBackColor );

	// draw text box centered inside the window
	Area fit = Area::proportionalFit( Area(Vec2i::zero(), mTextBox.getSize()), getWindowBounds(), true, false ); 

	gl::color( mFrontColor );
	gl::enableAlphaBlending();

	gl::pushModelView();
	gl::translate( fit.getUL() );

	// bind shader
	if(mSdfShader) {
		mSdfShader.bind();
		mSdfShader.uniform("tex0", 0);
	}

	mTextBox.draw();

	// unbind shader
	if(mSdfShader) mSdfShader.unbind();

	if(mShowWireframe) mTextBox.drawWireframe();
	
	gl::popModelView();
	gl::disableAlphaBlending();

	if(mShowBounds)
		mTextBox.drawBounds( fit.getUL() );
}
예제 #12
0
void RepulsionApp::setFboPositions( gl::Fbo &fbo )
{
	Surface32f pos( fbo.getTexture() );
	Surface32f::Iter it = pos.getIter();
	while( it.line() ){
		while( it.pixel() ){
			Vec3f r = mRoom.getRandRoomPos();
			float mass = Rand::randFloat( 20.0f, 30.0f );
			if( Rand::randFloat() < 0.05f ) 
				mass = Rand::randFloat( 50.0f, 60.0f );
			
			if( it.y() < 5  && it.x() < 50 )
				mass = Rand::randFloat( 300.0f, 5000.0f );
			else
				mass = Rand::randFloat( 50.0f, 300.0f );
			
			it.r() = r.x;
			it.g() = r.y;
			it.b() = r.z;
			it.a() = 100.0f;
		}
	}
	
	gl::Texture posTexture( pos );
	posTexture.bind();
	
	gl::setMatricesWindow( mFboSize, false );
	gl::setViewport( mFboBounds );
	
	fbo.bindFramebuffer();
	mPosInitShader.bind();
	mPosInitShader.uniform( "initTex", 0 );
	gl::drawSolidRect( mFboBounds );
	mPosInitShader.unbind();
	fbo.unbindFramebuffer();
}
예제 #13
0
void ObjLoaderApp::draw()
{
	gl::enableDepthWrite();
	gl::enableDepthRead();
	
	gl::clear( Color( 0.0f, 0.1f, 0.2f ) );
	glDisable( GL_CULL_FACE );

	gl::setMatrices( mMayaCam.getCamera() );

/*	Sphere boundingSphere = Sphere::calculateBoundingSphere( mMesh.getVertices() );
	glColor3f( 1.0f, 1.0f, 1.0f );
	gl::disableDepthWrite();
	mTexture->disable();
	mShader.unbind();
	gl::draw( boundingSphere, 30 );
	gl::enableDepthWrite();
*/
	mShader.bind();
	gl::pushMatrices();
		gl::rotate( mArcball.getQuat() );
		gl::draw( mVBO );
	gl::popMatrices();
}
예제 #14
0
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();
}
예제 #15
0
void StereoscopicRenderingApp::render()
{	
	float seconds = (float) getElapsedSeconds();

	// enable 3D rendering
	gl::enableDepthRead();
	gl::enableDepthWrite();

	// set 3D camera matrices
	gl::pushMatrices();
	gl::setMatrices( mCamera );

	if( mShaderPhong && mMeshTrombone && mMeshNote ) {
		// enable phong shading
		mShaderPhong.bind();	
		
		// draw trombone
		gl::pushModelView();
		{
			gl::color( Color(0.7f, 0.6f, 0.0f) );
			gl::rotate( Vec3f::yAxis() * 10.0f * seconds );
			gl::draw( mMeshTrombone );

			// reflection
			gl::scale( 1.0f, -1.0f, 1.0f );
			gl::draw( mMeshTrombone );
		}
		gl::popModelView();	

		// draw animated notes
		Rand rnd;
		for(int i=-100; i<=100; ++i) {
			rnd.seed(i);

			float t = rnd.nextFloat() * 200.0f + 2.0f * seconds;
			float r = rnd.nextFloat() * 360.0f + 60.0f * seconds;
			float z = fmodf( 5.0f * t, 200.0f ) - 100.0f;		

			gl::pushModelView();
			{
				gl::color( Color( CM_HSV, rnd.nextFloat(), 1.0f, 1.0f ) );

				gl::pushModelView();
				gl::translate( i * 0.5f, 0.15f + 1.0f * math<float>::abs( sinf(3.0f * t) ), -z );
				gl::rotate( Vec3f::yAxis() * r );
				gl::draw( mMeshNote );
				gl::popModelView();
				
				// reflection
				gl::pushModelView();
				gl::scale( 1.0f, -1.0f, 1.0f );
				gl::translate( i * 0.5f, 0.15f + 1.0f * math<float>::abs( sinf(3.0f * t) ), -z );
				gl::rotate( Vec3f::yAxis() * r );
				gl::draw( mMeshNote );
				gl::popModelView();
			}
			gl::popModelView();
		}

		mShaderPhong.unbind();
	}

	// draw grid
	gl::color( Color(0.8f, 0.8f, 0.8f) );
	for(int i=-100; i<=100; ++i) {
		gl::drawLine( Vec3f((float) i, 0, -100), Vec3f((float) i, 0, 100) );
		gl::drawLine( Vec3f(-100, 0, (float) i), Vec3f(100, 0, (float) i) );
	}

	// draw floor
	gl::enableAlphaBlending();
	gl::color( ColorA(1,1,1,0.75f) );
	gl::drawCube( Vec3f(0.0f, -0.5f, 0.0f), Vec3f(200.0f, 1.0f, 200.0f) );
	gl::disableAlphaBlending();

	// restore 2D rendering
	gl::popMatrices();
	gl::disableDepthWrite();
	gl::disableDepthRead();

	// render UI
	if( mDrawUI ) renderUI();
}
예제 #16
0
// Just create the latest thing
void svvimApp::draw() {
  
  // SvvimLogo
  if (mSvvimLogoPng)
    mSvvimLogoPng.bind(0);
  
  // Mask
  if (mMaskTexture)
    mMaskTexture.bind(1);
  
  //
  if (mImageTexture)
    mImageTexture.bind(2);
  
  // Clear to black
  gl::clear();

  /*
  if (mMaskTexture) {
    Area bounds = mMaskTexture.getBounds();
    
    Area displayArea = getWindowBounds();
    // displayArea.y1 = displayArea.y1 + displayArea.getHeight() * .05;
    // displayArea.y2 = displayArea.y2 - displayArea.getHeight() * .05;
    
    Rectf centeredRect = Rectf(mMaskTexture.getBounds()).getCenteredFit(displayArea, false);
    
    float coverAspectRatio = mMaskTexture.getAspectRatio();
    float windowAspectRatio = getWindowAspectRatio();
    
    if (coverAspectRatio > windowAspectRatio) {
      float scale = displayArea.getHeight()/centeredRect.getHeight();
      centeredRect.scaleCentered(scale);
    }
    else {
      float scale = displayArea.getWidth()/centeredRect.getWidth();
      centeredRect.scaleCentered(scale);
    }
    
    gl::draw(mMaskTexture, centeredRect);
  } */

  
  // Draw pool-water background cover
  if (mImageTexture) {
    Area bounds = mImageTexture.getBounds();

    Area displayArea = getWindowBounds();
    displayArea.y1 = displayArea.y1 + displayArea.getHeight() * .05;
    displayArea.y2 = displayArea.y2 - displayArea.getHeight() * .05;
    
    Rectf centeredRect = Rectf(mImageTexture.getBounds()).getCenteredFit(displayArea, true);

    float coverAspectRatio = mImageTexture.getAspectRatio();
    float windowAspectRatio = getWindowAspectRatio();
    
    if (coverAspectRatio > windowAspectRatio) {
      float scale = displayArea.getHeight()/centeredRect.getHeight();
      centeredRect.scaleCentered(scale);
    }
    else {
      float scale = displayArea.getWidth()/centeredRect.getWidth();
      centeredRect.scaleCentered(scale);
    }
    
    gl::draw(mCurrentBgTexture, centeredRect);
  }

  if (mShader) {
    float displacement = 10. - min(mAlpha * 300.0, 10.0);
    mShader.bind();
    mShader.uniform("displacement", displacement);
    mShader.uniform("maskTexture", 0);
    mShader.uniform("innerTexture", 2);
    mShader.uniform("fillColor", Vec3f(0.3, 0.3, 0.3));
    mShader.uniform("bounds", Vec2f(getWindowWidth(), getWindowHeight()));
    mShader.uniform("alpha", 6 * mAlpha);
  }
  
  if (mSvvimLogoPng) {
    Rectf centeredRect = Rectf(mSvvimLogoPng.getBounds()).getCenteredFit(getWindowBounds(), true);
    Rectf topRect = centeredRect;
    gl::draw(mSvvimLogoPng, centeredRect);
    centeredRect.y1 -= 200;
    centeredRect.y2 -= 200;
    //gl::draw(mSvvimLogoPng, centeredRect);
    centeredRect.y1 += 400;
    centeredRect.y2 += 400;
    //gl::draw(mSvvimLogoPng, centeredRect);
  }
  
  if (mShader)
    mShader.unbind();
  
  if (mMaskTexture)
    mMaskTexture.unbind();
  
  if (mImageTexture)
    mImageTexture.unbind();
  
  if (mSvvimLogoPng)
    mSvvimLogoPng.unbind();

}
예제 #17
0
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();
}
예제 #18
0
void GlowTestApp::draw()
{
    // clear out the window with black

    gl::clear( Color( 0, 0, 0 ) );


    // 일단 Fbo 를 하나 만들어서 그린다. 드로잉 컨텍스트가 완전 새로운게 되는듯? Fbo 에 대해 더 공부해볼 필요가 있당...
    // 뭔가 카메라 설정도 마구마구 해서

    mNormalFbo.bindFramebuffer();
    gl::clear( ColorA(0, 0, 0, 0 ) );
    gl::color(1.0, 1.0, 1.0);
    gl::drawSphere(Vec3f(200,100, 0), 50.0);
    gl::drawSphere(Vec3f(500,100, 0), 50.0);
    mNormalFbo.unbindFramebuffer();






    // 블러 때리는용 Fbo 를 만들어서 또 그린다. (지금은 그냥 오리지널만 써도 될듯.)

    mGlowFbo.bindFramebuffer();
    gl::setMatricesWindowPersp(getWindowSize());
    gl::clear( ColorA(0, 0, 0, 0 ) );
    gl::color(0.4, 0.2, 0.5);
    gl::drawSphere(Vec3f(200,100, 0), 50.0);


    mGlowFbo.unbindFramebuffer();


    // 텍스쳐 블러시킬 Fbo 를 만든다. 텍스쳐가 정면에 나와야 되니까 카메라 세팅을 신더 기본으로 해준다.
    // 블러 때리는용 Fbo 를 텍스쳐화 시켜 그린다.
    mBlurFbo.bindFramebuffer();
    gl::clear( ColorA(0, 0, 0, 0 ) );

    gl::setMatricesWindowPersp(getWindowSize());

    mGlowFbo.getTexture().bind(1);  // 얘를 바인딩 해야한다. 그래서 sampler 로 전달하구, 텍스쳐로 그려내야돼.
    mBlurShader.bind();
    mBlurShader.uniform("GlowFboTex", 1);   // glowfbo 를 전사한 텍스쳐를 sampler1d 로 보낸다.
    mBlurShader.uniform("sampleOffset", Vec2f(0.7, 0.3) * ( 3.0f / getWindowWidth() ) );

    gl::drawSolidRect( Rectf(0.0, 0.0, getWindowWidth(), getWindowHeight() ) );
    mBlurShader.unbind();
    mGlowFbo.getTexture().unbind();
    mBlurFbo.unbindFramebuffer();

    //  섞어보자.


    mMultiplyFbo.bindFramebuffer();
    gl::clear( ColorA(0, 0, 0, 0 ) );
    gl::setMatricesWindowPersp(getWindowSize());

    // 두가지 합칠 소스 가져오기
    mNormalFbo.getTexture().bind(1);
    mBlurFbo.getTexture().bind(2);


    mMultiShader.bind();
    mMultiShader.uniform("Tex1", 1);
    mMultiShader.uniform("Tex2", 2);
    gl::drawSolidRect( Rectf(0.0, 0.0, getWindowWidth(), getWindowHeight() ) );
    mMultiShader.unbind();
    mMultiplyFbo.unbindFramebuffer();

    // 최종적으로 블러된 Fbo 를 전사한다.


    //gl::draw(mMultiplyFbo.getTexture());


    // 뒤집힘 해결 테스트

    gl::drawSphere(Vec3f(200,100, 0), 50.0);
    gl::drawSphere(Vec3f(500,100, 0), 50.0);

    gl::draw(mNormalFbo.getTexture());


}
예제 #19
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();
}
예제 #20
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();
}
예제 #21
0
void PopGameApp::draw()
{
    if(getElapsedFrames()>200)return;
    
    gl::pushMatrices();
    
    
    gl::setMatrices( *mCamera );
    gl::enable(GL_DEPTH_TEST);
   
    gl::clear(ColorA(0.5,0.5,0.5,1));
 gl::enableDepthWrite();
	glEnable( GL_LIGHTING );
	updateShadowMap();
    
	gl::enableDepthRead();
	// clear out the window with black
    glEnable( GL_TEXTURE_2D );
 
    
    glEnable(GL_ALPHA_TEST);
    glAlphaFunc(GL_GREATER, 0.5);
	mShader.bind();
	mDepthFbo.bindDepthTexture(1);

  
	mShader.uniform( "shadowTransMatrix", mLight->getShadowTransformationMatrix( *mCamera ) );
    //gl::enable(GL_BLEND);
  	mLight->update( *mCamera );
    
    gl::pushMatrices();
    stage.int_draw();
    gl::popMatrices();
    
    
    
    gl::popMatrices();
   // gl::setMatrices( *mCamera );
    
    mShader.unbind();
    
    gl::disable (GL_DEPTH_TEST);
glDisable( GL_LIGHTING );
    glDisable (GL_ALPHA_TEST);
   glEnable(GL_BLEND);
    gl::enableAlphaBlending();
    
    stage2D.int_draw();
    glDisable(GL_BLEND);
    gl::disableAlphaBlending();
    
   
    
/*
    glDisable( GL_LIGHTING );
     
    gl::setMatricesWindow( getWindowSize() );
    Surface32f shadowMapSurface( mDepthFbo.getDepthTexture() );
    ip::hdrNormalize( &shadowMapSurface );
    gl::color( Color::white() );
    gl::draw( gl::Texture( shadowMapSurface ), Rectf( 0, 0, 128*2, 128*2 ) );
*/
}
/* 
 * @Description: render the final scene ( using all prior created FBOs and combine )
 * @param: none
 * @return: none
 */
void Base_ThreeD_ProjectApp::renderScreenSpace()
{	
	// use the scene we rendered into the FBO as a texture
	glEnable( GL_TEXTURE_2D );
	
	// show the FBO texture in the upper left corner
	gl::setMatricesWindow( getWindowSize() );
	
	switch (RENDER_MODE) 
	{
		case SHOW_STANDARD_VIEW:
		{
			mScreenSpace1.getTexture(0).bind(0);
            gl::drawSolidRect( Rectf( 0, getWindowHeight(), getWindowWidth(), 0) );
			mScreenSpace1.getTexture(0).unbind(0);
		}
            break;
			
		case SHOW_SSAO:
		{
			mSSAOMap.getTexture().bind(0);
			
			mBasicBlender.bind();
			
			mBasicBlender.uniform("ssaoTex", 0 );
			mBasicBlender.uniform("baseTex", 0 );
			gl::drawSolidRect( Rectf( 0, getWindowHeight(), getWindowWidth(), 0) );
			
			mBasicBlender.unbind();
			
			mSSAOMap.getTexture().unbind(0);
		}
            break;
			
		case SHOW_NORMALMAP:
		{
			mNormalDepthMap.getTexture().bind(0);
            gl::drawSolidRect( Rectf( 0, getWindowHeight(), getWindowWidth(), 0) );
			mNormalDepthMap.getTexture().unbind(0);
		}
            break;
			
		case SHOW_FINAL_SCENE:
		{
			pingPongBlur();
			
			gl::setMatricesWindow( getWindowSize() );
			
			mPingPongBlurV.getTexture().bind(0);
			mScreenSpace1.getTexture().bind(1);
			
			mBasicBlender.bind();
			
			mBasicBlender.uniform("ssaoTex", 0 );
			mBasicBlender.uniform("baseTex", 1 );
			gl::drawSolidRect( Rectf( 0, getWindowHeight(), getWindowWidth(), 0) );
			
			mBasicBlender.unbind();
			
			mScreenSpace1.getTexture().unbind(1);
			mPingPongBlurV.getTexture().unbind(0);
		}
			break;
	}
	
	glDisable(GL_TEXTURE_2D);
}
void GesichtertauschApp::draw() {
    
    glClearColor( 0, 0, 0, 1.0 );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    
    if ( ! mCameraTexture ) {
        return;
    }
        
//    gl::setMatricesWindow( getWindowSize() ),
    gl::setMatricesWindow(WINDOW_WIDTH, WINDOW_HEIGHT);
    gl::enableAlphaBlending();
    glScalef(-1.0, 1.0, 1.0);
    glTranslatef(-WINDOW_WIDTH, 0, 0);
    
    /* shader */
    // TODO make this more opt'd
    if (ENABLE_SHADER) {
        mShader.bind();
        const int STEPS = 32;
        float mThresholds[STEPS];// = {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0};
        for (int i=0; i < STEPS; ++i) {
            mThresholds[i] = float(i) / float(STEPS - 1);
        }
        mShader.uniform("thresholds", mThresholds, STEPS);   
        mShader.uniform( "tex0", 0 );
    }

    /* draw the webcam image */
    gl::color( BACKGROUND_IMAGE_COLOR );
    gl::draw( mCameraTexture, Rectf(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT) );
    mCameraTexture.disable();
    
    /* normalize texture coordinates */
    Vec2f mNormalizeScale = Vec2f(1.0 / float(WINDOW_WIDTH), 1.0 / float(WINDOW_HEIGHT));
    glMatrixMode(GL_TEXTURE);
    glPushMatrix();
    glScalef(mNormalizeScale.x, mNormalizeScale.y, 1.0);
    glMatrixMode(GL_MODELVIEW);
    
    /* draw orgiginal faces */
    if (mEntities.size() < 2) {
        gl::enableAlphaBlending();
        mCameraTexture.enableAndBind();
        for( vector<FaceEntity>::const_iterator mIter = mEntities.begin(); mIter != mEntities.end(); ++mIter ) {
            drawEntity(*mIter, FACE_COLOR_UNO);
        }    
        mCameraTexture.disable();
        gl::disableAlphaBlending();
    }
    
    /* HACK // swap faces */
    mCameraTexture.enableAndBind();
    if (mEntities.size() >= 2) {
        const FaceEntity A = mEntities[0];
        const FaceEntity B = mEntities[1];
        if (A.visible && B.visible) {
            FaceEntity mEntityA = FaceEntity();
            FaceEntity mEntityB = FaceEntity();
            
            mEntityA.border = B.border;
            mEntityB.border = A.border;
            mEntityA.slice = A.slice;
            mEntityB.slice = B.slice;
            mEntityA.visible = A.visible;
            mEntityB.visible = B.visible;
            mEntityA.ID = A.ID;
            mEntityB.ID = B.ID;
            
            drawEntity(mEntityA, FACE_COLOR_DUO);
            drawEntity(mEntityB, FACE_COLOR_DUO);
        }
    }

    /* restore texture coordinates */
    glMatrixMode(GL_TEXTURE);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);

    mCameraTexture.disable();

    /* shader */
    if (ENABLE_SHADER) {
        mShader.unbind();
    }

    /* mask */
    float MASK_LEFT_TOP = 1;
    float MASK_LEFT_BOTTOM = 1;
    float MASK_RIGHT_TOP = 1;
    float MASK_RIGHT_BOTTOM = 1;
    
    gl::color(0, 0, 0, 1);

    Path2d mPathLeft;
    mPathLeft.moveTo(0, 0);
    mPathLeft.lineTo(MASK_LEFT_TOP, 0);
    mPathLeft.lineTo(MASK_LEFT_BOTTOM, WINDOW_HEIGHT);
    mPathLeft.lineTo(0, WINDOW_HEIGHT);
    mPathLeft.close();    
    gl::drawSolid(mPathLeft);
    
    Path2d mPathRight;
    mPathRight.moveTo(WINDOW_WIDTH, 0);
    mPathRight.lineTo(WINDOW_WIDTH-MASK_RIGHT_TOP, 0);
    mPathRight.lineTo(WINDOW_WIDTH-MASK_RIGHT_BOTTOM, WINDOW_HEIGHT);
    mPathRight.lineTo(WINDOW_WIDTH, WINDOW_HEIGHT);
    mPathRight.close();    
    gl::drawSolid(mPathRight);

    /* draw entity IDs */
    const bool DRAW_ENTITY_ID = false;
    if (DRAW_ENTITY_ID) {
        for( vector<FaceEntity>::const_iterator mIter = mEntities.begin(); mIter != mEntities.end(); ++mIter ) {
            const FaceEntity mEntity = *mIter;
            std::stringstream mStr;
            mStr << mEntity.ID;
            gl::drawStringCentered(mStr.str(), mEntity.border.getCenter(), Color(1, 0, 0), mFont);
        }    
    }
        
    /* gooey */
    mGui->draw();
}
예제 #24
0
void BrainbowApp::draw()
{
	gl::setViewport( getWindowBounds() );
    
    // SCREENPULSE
    // changes every 12.5 seconds
    float gray = (cos(getElapsedSeconds()/4)*.3)/2 ;
    float otherCol = (sin(getElapsedSeconds()/4)*.2)/2;
    
    screenCol = Vec3f (lightFade+gray, lightFade, (lightFade*2)-otherCol);
    
    if (sceneOne)
        gl::clear( Color(lightFade+gray, lightFade, (lightFade*2)-otherCol) );
    if (sceneTwo)
        gl::clear( Color(1, 1, 1) );
    
    
    // FADE IN INTRO
    if (lightFade < .5){
        lightFade += .0005;
    }
    
    if (mHands.empty())
        mLight->disable();
    
    updateShadowMap();
    
    gl::enableDepthRead();
    gl::enableDepthWrite();
    mShader.bind();
    glEnable( GL_TEXTURE_2D );
	mDepthFbo.bindDepthTexture();
    mShader.bind();
    
    
    // FIRST SCENE
    if (sceneOne){
        
        // disc
        if (zshift > 0){
            glPushMatrix();
            glTranslated( 640, 400, zshift - 200);
            if (shift2 && discOp > 1)
                glScalef(discOp, discOp, 0);
            //    cout << discOp << endl;
            mDisc.draw();
            glPopMatrix();
        }
        
        //cloud
        glPushMatrix();
        glTranslated( getWindowWidth() * 0.5f, getWindowHeight() * 0.5f, zshift );
        //    if (lightFade > .45f)
        mCloud.update(scaledX, scaledY, scaledZ, diamondFade, 1);
        glPopMatrix();
        
        if (drawDiamond){
            glPushMatrix();
            glTranslated( getWindowWidth() * 0.5f, getWindowHeight() * 0.5f, zshift);
            mDiamond.draw();
            glPopMatrix();
        }
    }
    
    // SECOND SCENE
    if (sceneTwo){
        
        mLight->lookAt( Vec3f(scaledX, scaledY, scaledZ +200), Vec3f (getWindowWidth()*.05, getWindowHeight() * 0.5f, 0.0f ));
        
        // cursor
        glPushMatrix();
        glTranslated( scaledX, scaledY, scaledZ );
        mCur.draw();
        
        if (scaledZ < 375 && scaledZ > 350)
            gl::drawSphere(Vec3f(0,0,0), (scaledZ-350)*.4);
        if (scaledZ >= 375)
            gl::drawSphere(Vec3f(0,0,0), 25*.4);
        glPopMatrix();
        
        
        // rotate whole scene; implement this later:
        
        //        if (targetFilled){
        //            glPushMatrix();
        //            glRotatef(getElapsedSeconds()*10, Vec3f (640, 400, 350) );
        //        }
        for (int i = 0; i < cubes.size() ; i++){
            glPushMatrix();
            glTranslatef(cubes[i].getLocation());
            cubes[i].update(.01f, screenCol);
            glPopMatrix();
        }
        offCounter = 0;        
        for (int i = 0; i < targets.size() ; i++){
            glPushMatrix();
            glTranslatef(targets[i].getLocation());
            targets[i].update(.01f, handPos, screenCol);
            if (targets[i].getBoxed() && targets[i].getBoxNumber() < 15 ){
                addCube(targets[i].getLocation().x, targets[i].getLocation().y, targets[i].getLocation().z);
                targets[i].addBox();
                if (targets[i].getBoxNumber() == 15)
                mAudio.playTraz("box");   
            }
            
            glPopMatrix();
            if (targets[i].getChargeSound()){
                if (!mAudio.isPlaying("charge")){
                    offCounter = 0;
                    mAudio.playTraz("charge");
                }
            }
            //stop charge if deactivated
            if (!targets[i].getChargeSound()){
                offCounter++;
            }
            if (offCounter == targets.size()){
                mAudio.stopTraz("charge");
            }
        }
        //  (from above)
        //   if (targetFilled)
        //   glPopMatrix();
        //
        
        //cloud
        glPushMatrix();
        glTranslated( getWindowWidth() * 0.5f, getWindowHeight() * 0.5f, zshift );
        mCloud.update(0, 0, 0, 0, 2);
        glPopMatrix();
    }
    
    mShader.unbind();
    mDepthFbo.unbindTexture();
    
    //    writeImage( getHomeDirectory() / ("image_" + toString( getElapsedFrames() ) + ".png"), copyWindowSurface() );
	
}
void DelaunayMeshMaker::draw()
{
	gl::clear();

	gl::pushMatrices();

	gl::pushModelView();
		gl::color( ColorA::white() );

		if( mMesh.getNumTriangles() > 0 ){
			if( mApplyPhongShading )
				mPhongShader.bind();

			gl::enableDepthRead();
			gl::enableDepthWrite();

			gl::disableAlphaBlending();

			if( mDrawWireframe )
				gl::enableWireframe();

			gl::draw( mVboMesh );

			if( mDrawWireframe )
				gl::disableWireframe();

			if( mApplyPhongShading )
				mPhongShader.unbind();
		}

		if( mAlpha > 0.0f ){
			gl::disableDepthRead();
			gl::disableDepthWrite();

			gl::enableAlphaBlending();

			gl::color( ColorA( 1,1,1, mAlpha ) );
			gl::draw( mSurface );
		}
	gl::popModelView();

	gl::popMatrices();

	if( mTesselator->isRunning() ){
		gl::disableDepthRead();
		gl::disableDepthWrite();

		gl::enableAlphaBlending();

		gl::color( ColorA(0.0f, 0.0f, 0.0f, 0.5f ) );
		gl::drawSolidRect( Rectf( 0, 0, app::getWindowWidth(), app::getWindowHeight() ) );

		gl::pushModelView();
			gl::translate( app::getWindowSize()/2 );
			double time = getElapsedSeconds();
			double fraction = time - (int) time;
			int numFractions = 12;

			for(int i=0;i<numFractions;++i) {
				float a = (float) (fraction + i * (1.0f / (float)numFractions));
				a -= (int) a;

				gl::pushModelView();
				gl::rotate( i * ( -360.0f/(float)numFractions ) );
				gl::color( ColorA(1,1,1,1-a) );
				gl::drawSolidRect( Rectf(-6.0f, -44.0f, +6.0f, -31.0f) );
				gl::popModelView();
			}
		gl::popModelView();
	}

	mParams.draw();
}
예제 #26
0
void PopGameApp::setup()
{
    
   
    
    speed2 =3.5;
    setWindowSize(1920,1080);
    //setWindowSize(1080/2,1920/2);
    setWindowPos(0, 0);
	mCamera = new CameraPersp( getWindowWidth(), getWindowHeight(), 45.0f );
	mCamera->lookAt( Vec3f( 0, -300, -400 ), Vec3f( 0, 0, 50 ) );
	mCamera->setPerspective( 80.0f, getWindowAspectRatio(),200.0f, 4000.0f );

    
    mLight = new gl::Light( gl::Light::POINT, 0 );
  
	mLight->lookAt( Vec3f(1000,-1000, -2000 ), Vec3f( 0, 1000, 0 ) );
    mLight->setShadowParams(60.0f,2000.f, 3500.0f );
	mLight->update( *mCamera );
	mLight->enable();
    

    
  
    mShader = gl::GlslProg( loadAsset("shadowMap_vert.glsl"),loadAsset("shadowMap_frag.glsl") );
    
	mShader.bind();
	mShader.uniform( "depthTexture", 1 );
    mShader.uniform( "difTexture", 0 );
    mShader.unbind();
    
     initShadowMap();
    
   
   
    groundHolder.setup();
    stage.addChild(&groundHolder);
    
    enemyHandler.setup();
    stage.addChild(&enemyHandler);
    BulletHandler::getInstance()->enemyHandler =&enemyHandler;
   
    
    
    
    plane =new Hero();
    plane->load("plane.png","planeh.png");
    plane->setAlign(neuro::ALIGN_CENTER);
    
    plane->z = 0;
   
   
    
 
    
     stage.addChild(plane);
    prevTime = cinder::app::getElapsedSeconds();
    
    BulletHandler::getInstance()->stage =&stage;
    
    
    logo =new Image();
    logo->load("logo.png");
  // logo->rotationX =-3.1415;
    logo->setAlign(neuro::ALIGN_BOTTOM_LEFT);
    logo->x =0;
    logo->y =1080*2;
    //logo->scaleX =logo->scaleY =logo->scaleZ =4;
    stage2D.scaleX=stage2D.scaleY =0.5;
    stage2D.addChild(logo);
    
}
예제 #27
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 ++;
	}
}
void RodSoundApp::draw() {
  while (running &&
//         app::getElapsedSeconds() - tAtLastDraw < 1.0/app::getFrameRate() &&
         fe.nextTimestep(c) > 1.0 / (real) SampleRate) {
    update();
  }
  tAtLastDraw = app::getElapsedSeconds();
  
  PROFILER_START("Draw");
  
	// Clear out the window with grey
	gl::clear(Color(0.45, 0.45, 0.5));
  
  // Enable alpha blending and depth testing
  gl::enableAlphaBlending();
	gl::enableDepthRead(true);
	gl::enableDepthWrite(true);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
  // Draw framerate counter
  gl::setMatricesWindow(getWindowSize());
  std::stringstream ss;
  ss << getAverageFps();
  gl::drawStringRight(ss.str(),
                      Vec2c(getWindowWidth()-toPixels(10), getWindowHeight()-toPixels(20)),
                      Color(0.0, 0.0, 0.0),
                      Font("Arial", toPixels(12)));
  
  // Set projection/modelview matrices
  gl::setMatrices(cam);
  
  // Draw the rod and the normal of the bishop frame
  for(int i=0; i<r->numEdges(); i++) {
    Vec3c p0 = EtoC(r->cur().POS(i));
    Vec3c p1 = EtoC(r->cur().POS(i+1));
    gl::drawLine(p0, p1);
    gl::color(1.0, 1.0, 0.0);
    gl::lineWidth(1.0);
    Vec3c u = EtoC(r->cur().u[i]);
    gl::drawLine((p0+p1)/2.0, (p0+p1)/2.0+u*(p1-p0).length()*2.0);
  }
  
  m.apply();
  
  l->setDiffuse(Color::white());
  l->setAmbient(Color::white());
  l->setPosition(Vec3c(0.0, 50.0, 0.0));
  l->enable();
  
  diffuseProg.bind();
  for (int i=0; i<r->numCPs(); i++) {
    gl::pushModelView();
    gl::translate(EtoC(r->cur().POS(i)));
    spheredl->draw();
    gl::popModelView();
  }
  diffuseProg.unbind();
  
  rodProg.bind();

  floorTex.enableAndBind();
  gl::draw(floor);
  floorTex.disable();
  
  rodProg.unbind();
  
  // Draw rod edges
  rodProg.bind();
  rodTex.enableAndBind();
  for (int i=0; i<r->numEdges(); i++) {
    gl::pushModelView();
    Vec3c v = EtoC(r->cur().edge(i).normalized());
    
    gl::translate(EtoC(r->cur().POS(i)));
    Quaternion<real> q(Vec3c(0.0, 1.0, 0.0), v);
    real angle = acos(std::max((real)-1.0, std::min((real)1.0, (q*Vec3c(-1.0, 0.0, 0.0)).dot(EtoC(r->cur().u[i])))));
    if ((q*Vec3c(-1.0, 0.0, 0.0)).dot(EtoC(r->cur().v(i))) > 0.0) angle = -angle;
    gl::rotate(Quaternion<real>(v, angle));
    gl::rotate(q);
    gl::rotate(Vec3c(0.0, r->cur().rot(i)*180.0/constants::pi, 0.0));
    gl::scale(1.0, r->cur().edgeLength(i), 1.0);
    cylinderdl->draw();
    gl::popModelView();
  }
  rodTex.unbind();
  rodProg.unbind();

  for (RodEnergy* e : energies) {
    e->draw(c.timestep());
  }
  integrator->draw();
 
  fe.record(c);
  
  PROFILER_STOP("Draw");
}
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();
}
예제 #30
0
void BrainbowApp::setup()
{
    // LOAD AUDIO
    mAudio = AudioCont();
    mAudio.setUp();
    
    // START SCENE 1
    sceneOne = true;
    sceneTwo = false;
    
    // Set up OpenGL
    
	gl::enableAlphaBlending();
	gl::enableDepthRead();
	gl::enableDepthWrite();
    
    gongTimer.start();
    ballTimer.start();
    
    // LIGHTING
    //here
    glPolygonOffset( 1.0f, 1.0f );
	glEnable( GL_LIGHTING );
	glEnable( GL_DEPTH_TEST );
    
    
    mLight = new gl::Light( gl::Light::POINT, 0 );
	mLight->lookAt( Vec3f( 1, 5, 1 ), Vec3f (getWindowWidth(), getWindowHeight() * 0.5f, 0.0f ));
    mLight->setAmbient( Color( 0.3f, 0.3f, 0.3f ) );
	mLight->setDiffuse( Color( 1.0f, 1.0f, 1.0f ) );
	mLight->setSpecular( Color( 1.0f, 1.0f, 1.0f ) );
	mLight->setShadowParams( 60.0f, 0.5f, 8.0f );
    //	mLight->update( *mCamera );
	mLight->enable();
    
    
    //LOAD SHAPES
    colorSat = 1.0f;
    
	sphereMaterial.setSpecular( ColorA(colorSat-0.3f, colorSat, colorSat, .4f ) );
	sphereMaterial.setDiffuse( ColorA(colorSat-0.3f, colorSat, colorSat, .4f ) );
	sphereMaterial.setAmbient( ColorA(colorSat-0.3f, colorSat, colorSat, .05f ) );
	sphereMaterial.setShininess( 1.0f );
    
    sphereMaterial.setEmission(ColorA(1, 1, 1, 1 ));
    gl::Material cylMaterial;
    cylMaterial.setSpecular( ColorA(0, 1.0f, 1.0f, .2f ));
	cylMaterial.setDiffuse( ColorA(0, 1.0f, 1.0f, .2f ) );
	cylMaterial.setAmbient( ColorA(0, 1.0f, 1.0f, .2f ) );
	cylMaterial.setShininess( 600.0f );
    cylMaterial.setEmission(ColorA(1, 1, 1, 1 ));
    
    gl::Material curMaterial;
    curMaterial.setSpecular( ColorA(1, .5, 0, .5f ));
	curMaterial.setDiffuse( ColorA(1, .5, 0, .5f ) );
	curMaterial.setAmbient( ColorA(1, 1.0f, 1.0f, .05f ) );
	curMaterial.setShininess( 600.0f );
    curMaterial.setEmission(ColorA(1, 1, 1, 1 ));
    
    
	discMaterial.setSpecular( ColorA(colorSat-0.3f, colorSat, colorSat, .4f ) );
	discMaterial.setDiffuse( ColorA(colorSat-0.3f, colorSat, colorSat, .4f ) );
	discMaterial.setAmbient( ColorA(colorSat-0.3f, colorSat, colorSat, .05f ) );
	discMaterial.setShininess( 600.0f );
    discMaterial.setEmission(ColorA(1, 1, 1, 1 ));
    
    initShadowMap();
    
    mCloud = SphereCloud(0, 70);
    
    mDiamond = gl::DisplayList( GL_COMPILE );
    mDiamond.newList();
    gl::drawSphere(Vec3f(0, 0, 0), 300, 4);
    mDiamond.endList();
    mDiamond.setMaterial( sphereMaterial );
    
    mCyl = gl::DisplayList( GL_COMPILE );
    mCyl.newList();
    //    gl::drawCylinder(200, 200, 200);
    gl::drawColorCube(Vec3f(0, 0, 0), Vec3f(300, 300, 300));
    mCyl.endList();
    mCyl.setMaterial(cylMaterial);
    
    mCur = gl::DisplayList( GL_COMPILE );
    mCur.newList();
    gl::drawSphere(Vec3f(0, 0, 0), 5);
    mCur.endList();
    mCur.setMaterial(curMaterial);
    
    mDisc = gl::DisplayList( GL_COMPILE );
    mDisc.newList();
    gl::drawSolidCircle(Vec2f(0, 0), 60, 6);
    mDisc.endList();
    mDisc.setMaterial( discMaterial );
	
	// START LEAP
	mLeap 		= LeapSdk::Device::create();
	mCallbackId = mLeap->addCallback( &BrainbowApp::onFrame, this );
    
    
    mShader = gl::GlslProg( loadResource( RES_SHADOWMAP_VERT ), loadResource( RES_SHADOWMAP_FRAG ) );
	mShader.bind();
	mShader.uniform( "depthTexture", 0 );
}