Exemplo n.º 1
0
void gpuPSApp::resetFBOs(){
	mCurrentFBO = 0;
	mOtherFBO = 1;
	mFBO[0].bindFramebuffer();
	mFBO[1].bindFramebuffer();
	
	// Attachment 0 - Positions
	glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
	gl::setMatricesWindow( mFBO[0].getSize(), false );
	gl::setViewport( mFBO[0].getBounds() );
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	mPositions.enableAndBind();
	gl::draw( mPositions, mFBO[0].getBounds() );
	mPositions.unbind();
	
	// Attachment 1 - Velocities
	glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	mVelocities.enableAndBind();
	gl::draw( mVelocities, mFBO[0].getBounds() );
	mVelocities.unbind();
	
	mFBO[1].unbindFramebuffer();
	mFBO[0].unbindFramebuffer();
	mPositions.disable();
	mVelocities.disable();
}
Exemplo n.º 2
0
void TutorialApp::draw()
{
    if(isFirst) {
        gl::clear( Color( 0, 0, 0 ), true );
        isFirst = false;
    }

    gl::enableAlphaBlending();
	
	if( mDrawImage ){
		mTexture.enableAndBind();
		gl::draw( mTexture, getWindowBounds() );
	}
    
//	if( mDrawParticles ){
		glDisable( GL_TEXTURE_2D );
		mParticleController.draw();
//	}
    
    if( mDrawImage ){
        mOverlay.enableAndBind();
        gl::draw( mOverlay, getWindowBounds() );
    }

//	if( mSaveFrames ){
//		writeImage( getHomeDirectory() / ( "image_" + toString( getElapsedFrames() ) + ".png" ), copyWindowSurface() );
//	}
}
void QuaternionAccumApp::drawBall()
{
	Vec3f pos = mSpline.getPosition( mSplineValue );
	Vec3f delta = pos - mLastPos;
	// our axis of rotation is the normal to the spline at this point
	Vec3f normal = Vec3f( delta.z, 0, -delta.x );
	
	// rotation amount (in radians) is the distance we've traveled divided by the radius of the ball
	float rotation = delta.length() / BALL_RADIUS;
	if( rotation ) {
		// increment our quaternion by a new quaternion representing how much rotating we did since the last frame
		Quatf incQuat( normal, rotation );
		mQuat *= incQuat;
		mQuat.normalize();
	}
	
	gl::translate( Vec3f( 0.0f, BALL_RADIUS, 0.0f ) + pos );
	gl::scale( Vec3f( BALL_RADIUS, BALL_RADIUS, BALL_RADIUS ) );
	gl::rotate( mQuat );
	
	gl::color( Color( 1, 1, 1 ) );
	mBallTexture.enableAndBind();
	gl::drawSphere( Vec3f::zero(), 1.0f, 60 );
	mBallTexture.disable();
	
	mLastPos = pos;
}
Exemplo n.º 4
0
void rayMarcherApp::draw()
{
    glClearColor( 0, 0, 0, 0 );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glEnable( GL_DEPTH_TEST );
    glEnable( GL_LIGHTING );
    glDepthMask( GL_TRUE );
    glDisable( GL_TEXTURE_2D );

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

    gl::setMatricesWindow( getWindowSize() );

    // draw as much of the texture as we've rendered
    glDisable( GL_LIGHTING );
    glDepthMask( GL_TRUE );
    glDisable( GL_DEPTH_TEST );

    glColor3f( 1, 1, 1 );
    mImageTexture.enableAndBind();
    glBegin( GL_QUADS );
    glTexCoord2f( mImageTexture.getLeft(), mImageTexture.getTop() );
    glVertex2f( 0, 0 );
    glTexCoord2f( mImageTexture.getLeft(), mImageTexture.getBottom() * mCurrentLine / mImageTexture.getHeight() );
    glVertex2f( 0, mCurrentLine );
    glTexCoord2f( mImageTexture.getRight(), mImageTexture.getBottom() * mCurrentLine / mImageTexture.getHeight() );
    glVertex2f( mImageTexture.getWidth(), mCurrentLine );
    glTexCoord2f( mImageTexture.getRight(), mImageTexture.getTop() );
    glVertex2f( mImageTexture.getWidth(), 0 );
    glEnd();
}
Exemplo n.º 5
0
void BloomingNeonApp::render()
{
	// get the current viewport
	Area viewport = gl::getViewport();

	// adjust the aspect ratio of the camera
	mCamera.setAspectRatio( viewport.getWidth() / (float) viewport.getHeight() );
	
	// render our scene (see the Picking3D sample for more info)
	gl::pushMatrices();

		gl::setMatrices( mCamera );
		gl::enableDepthRead();
		gl::enableDepthWrite();
		
		mTexture.enableAndBind();
			mShaderPhong.bind();
			mShaderPhong.uniform("tex0", 0);
				gl::pushModelView();
				gl::multModelView( mTransform );
					gl::color( Color::white() );
					gl::draw( mMesh );
				gl::popModelView();		
			mShaderPhong.unbind();
		mTexture.unbind();

		gl::disableDepthWrite();
		gl::disableDepthRead();

	gl::popMatrices();
}
Exemplo n.º 6
0
void LEDCamApp::draw()
{
	// clear out the window with black
	gl::clear( kClearColor ); 
	
	if( !mTexture ) return;
	mFbo.bindFramebuffer();
	mTexture.enableAndBind();
	mShader.bind();
	float aspect = kWindowHeight/kWindowWidth;
	cout << "Aspect: " << aspect << " \n";
	mShader.uniform( "aspect", aspect );
	mShader.uniform( "tex", 0 );
	mShader.uniform( "bright", 3.0f );
	mShader.uniform( "spacing", 3 );
	mShader.uniform( "ledCount", 100.0f );
	gl::drawSolidRect( getWindowBounds() );
	mTexture.unbind();
	mShader.unbind();
	mFbo.unbindFramebuffer();
	
	gl::Texture fboTexture = mFbo.getTexture();
	fboTexture.setFlipped();
	gl::draw( fboTexture );

}
void AudioVisualizerApp::draw()
{
	gl::clear();

	// use camera
	gl::pushMatrices();
	gl::setMatrices(mCamera);
	{
		// bind shader
		mShader.bind();
		mShader.uniform("uTexOffset", mOffset / float(kHistory));
		mShader.uniform("uLeftTex", 0);
		mShader.uniform("uRightTex", 1);

		// create textures from our channels and bind them
		mTextureLeft = gl::Texture(mChannelLeft, mTextureFormat);
		mTextureRight = gl::Texture(mChannelRight, mTextureFormat);

		mTextureLeft.enableAndBind();
		mTextureRight.bind(1);

		// draw mesh using additive blending
		gl::enableAdditiveBlending();
		gl::color( Color(1, 1, 1) );
		gl::draw( mMesh );
		gl::disableAlphaBlending();

		// unbind textures and shader
		mTextureRight.unbind();
		mTextureLeft.unbind();
		mShader.unbind();
	}
	gl::popMatrices();
}
Exemplo n.º 8
0
void FastTrailsApp::draw()
{
	// clear window
	gl::clear(); 

	// set render states
	gl::enableWireframe();
	gl::enableAlphaBlending();

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

	// enable 3D camera
	gl::pushMatrices();
	gl::setMatrices( mCamera.getCamera() );

	// draw VBO mesh using texture
	mTexture.enableAndBind();
	gl::drawRange( mVboMesh, 0, mTrail.size(), 0, mTrail.size()-1 );
	mTexture.unbind();

	// restore camera and render states
	gl::popMatrices();

	gl::disableDepthWrite();
	gl::disableDepthRead();

	gl::disableAlphaBlending();
	gl::disableWireframe();
}
Exemplo n.º 9
0
void MemExploreApp::draw()
{
  mTexture = gl::Texture(mDataPointer, GL_RGBA, mVolumeDim * mTilesDim, mVolumeDim * mTilesDim);
  mTexture.setWrap(GL_REPEAT, GL_REPEAT);
  mTexture.setMinFilter(GL_NEAREST);
  mTexture.setMagFilter(GL_NEAREST);
  
  float frustum[6];
  mCamera.getFrustum(&frustum[0], &frustum[1], &frustum[2], &frustum[3], &frustum[4], &frustum[5]);

  mFbo.bindFramebuffer();
  gl::setMatricesWindow(mFbo.getSize(), false);

  mProgram.bind();
  mProgram.uniform("uTexture", 0);
  mProgram.uniform("uVolumeDim", mVolumeDim);
  mProgram.uniform("uTilesDim", mTilesDim);
  mProgram.uniform("uTime", (float)getElapsedSeconds());
  mProgram.uniform("uEyePoint", mCamera.getEyePoint());
  mProgram.uniform("uXAxis", mCamera.getOrientation() * Vec3f::xAxis());
  mProgram.uniform("uYAxis", mCamera.getOrientation() * Vec3f::yAxis());
  mProgram.uniform("uViewDistance", mCamera.getAspectRatio() / abs(frustum[2] - frustum[0]) * mCamera.getNearClip());
  mProgram.uniform("uNegViewDir", -mCamera.getViewDirection().normalized());
  mProgram.uniform("uAspectRatio", mCamera.getAspectRatio());
  mTexture.enableAndBind();
  gl::drawSolidRect(mFbo.getBounds());
  mTexture.unbind();
  mProgram.unbind();
  
  mFbo.unbindFramebuffer();
  
  gl::setMatricesWindow(getWindowSize());
  gl::draw(mFbo.getTexture(), getWindowBounds());
}
void millionParticlesApp::initFBO()
{
    mPos = 0;
    mBufferIn = 0;
    mBufferOut = 1;

    mFbo[0].bindFramebuffer();
    mFbo[1].bindFramebuffer();

    //Positionen
    glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);

    gl::setMatricesWindow( mFbo[0].getSize(), false );
    gl::setViewport( mFbo[0].getBounds() );

    glClearColor(0.0f,0.0f,0.0f,1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    mPosTex.enableAndBind();
    gl::draw(mPosTex,mFbo[0].getBounds());
    mPosTex.unbind();

    //velocity buffer
    glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    mVelTex.enableAndBind();
    gl::draw(mVelTex,mFbo[0].getBounds());
    mVelTex.unbind();

    //particle information buffer
    glDrawBuffer(GL_COLOR_ATTACHMENT2_EXT);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    mInfoTex.enableAndBind();
    gl::draw(mInfoTex,mFbo[0].getBounds());
    mInfoTex.unbind();

    mFbo[1].unbindFramebuffer();
    mFbo[0].unbindFramebuffer();

    mPosTex.disable();
    mVelTex.disable();
    mInfoTex.disable();
}
Exemplo n.º 11
0
void VboSampleApp::draw()
{
    // this pair of lines is the standard way to clear the screen in OpenGL
    gl::clear( Color( 0.15f, 0.15f, 0.55f ) );
    gl::scale(Vec3f(10.0f+8.0f*sin(getElapsedSeconds()*2.0f), 10.0f+8.0f*sin(getElapsedSeconds()*2.0f), 10.0f+8.0f*sin(getElapsedSeconds()*2.0f)));
    mTexture.enableAndBind();
    gl::draw( mVboMesh );
    // Log("drawn texture %d", mTexture.getTextureId());
}
Exemplo n.º 12
0
void EarthquakeApp::draw()
{
	glClearColor( 1.0f, 0.0f, 0.0f, 1.0f );
	
	gl::enableAlphaBlending();
	gl::enableDepthRead( true );
	gl::enableDepthWrite( true );
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	
	glEnable( GL_TEXTURE_2D );
	glDisable( GL_TEXTURE_RECTANGLE_ARB );
	gl::GlslProg::unbind();
	
	glColor4f( 1, 1, 1, 1 );
	mStars.enableAndBind();
	gl::drawSphere( Vec3f( 0, 0, 0 ), 15000.0f, 64 );
	
	//gl::rotate( Quatf( Vec3f::zAxis(), -0.2f ) );
	//gl::rotate( Quatf( Vec3f::yAxis(), mCounter*0.1f ) );
	
	if( mShowEarth ){
		mEarthShader.bind();
		mEarthShader.uniform( "texDiffuse", 0 );
		mEarthShader.uniform( "texNormal", 1 );
		mEarthShader.uniform( "texMask", 2 );
		mEarthShader.uniform( "counter", mCounter );
		mEarthShader.uniform( "lightDir", mLightDir );
		mEarth.draw();
		mEarthShader.unbind();
	}
	
	
	glDisable( GL_TEXTURE_2D );
	
	
	glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );

	if( mShowQuakes ){
		mQuakeShader.bind();
		mQuakeShader.uniform( "lightDir", mLightDir );
		mEarth.drawQuakeVectors();
		mQuakeShader.unbind();
	}
	
	if( mShowText ){
		gl::enableDepthWrite( false );
		glEnable( GL_TEXTURE_2D );
		//mEarth.drawQuakeLabelsOnBillboard( sBillboardRight, sBillboardUp );
		mEarth.drawQuakeLabelsOnSphere( mPov.mEyeNormal, mPov.mDist );
		glDisable( GL_TEXTURE_2D );
	}
	
	if( mSaveFrames ){
		//writeImage( getHomeDirectory() / "CinderScreengrabs" / "Highoutput_" + toString( mCurrentFrame ) + ".png", copyWindowSurface() );
		mCurrentFrame++;
	}
}
Exemplo n.º 13
0
void ocvCaptureApp::draw()
{
	if (mWriting) {
		writeImage( "C:/movie/test/" + toString<int>(getElapsedFrames()) + ".jpg", copyWindowSurface() );
	}

	gl::clear();
	//gl::enableAlphaBlending( false );
	//gl::enableAlphaTest	(0.5f,GL_GREATER);
	//gl::enableAdditiveBlending ();


	gl::pushMatrices ();
	//gl::rotate(90);
	//gl::color(0.0/255.0,57.0/255.0,255.0/255.0);


	//if( mTexture )
	//	gl::draw( mTexture, Rectf( 0.0, 0.0, 1920, 1080 ) );

	if (mTexture) {
		// Vertices of quadrilateral
		Vec2f vert0 = mV0 + mOS0; //(0, 0);
		Vec2f vert1 = mV1 + mOS1; //(mW, 0);
		Vec2f vert2 = mV2 + mOS2; //(mW, mH);
		Vec2f vert3 = mV3 + mOS3; //(0, mH);

		// Bind texture to draw with it
		mTexture.enableAndBind();

		// Draw the mask by drawing two triangles, 
		// setting the texture coordinate before each vertex
		glBegin(GL_QUADS);
		{

			glTexCoord2f(0, 0);
			gl::vertex(vert0);
			glTexCoord2f(1, 0);
			gl::vertex(vert1);
			glTexCoord2f(1, 1);
			gl::vertex(vert2);
			glTexCoord2f(0, 1);
			gl::vertex(vert3);
		}
		glEnd();
	}


	//gl::draw(mMaskTexture);
	gl::popMatrices ();

	//if (mMaskTexture)
	//	gl::draw(mMaskTexture,Rectf( 0.0, 0.0, mW, mH ));
	//	mWriter.addFrame( copyWindowSurface() );

}
Exemplo n.º 14
0
void AudioObjApp::draw()
{
	gl::clear( Color( 0, 0, 0 ) );
    gl::enableAlphaBlending();
    gl::enableDepthRead();
    gl::enableDepthWrite();
    
    gl::pushMatrices();

	gl::setMatrices( mMayaCam.getCamera() );
	
	if ( mFeature && mFeatureTex )
	{
		mShader->bind();
		mFeatureTex.enableAndBind();
		mShader->uniform( "dataTex",		0 );
		mShader->uniform( "texWidth",		(float)mFeatureTex.getWidth() );
		mShader->uniform( "texHeight",		(float)mFeatureTex.getHeight() );
		mShader->uniform( "soundDataSize",  (float)mFeature->getSize() );
		mShader->uniform( "spread",         mFeatureSpread );
		mShader->uniform( "spreadOffset",   mFeatureSpreadOffset );
        mShader->uniform( "time",           (float)getElapsedSeconds() );
		mShader->uniform( "tintColor",      mObjColor );
	}
    
    if ( mRenderWireframe )
        gl::enableWireframe();
    
	gl::color( Color(1.0f, 0.0f, 0.0f ) );
    
	if ( mVbo )
	    gl::draw( mVbo );

    if ( mRenderWireframe )
        gl::disableWireframe();
    
	mShader->unbind();
	mFeatureTex.unbind();

	gl::color( Color::white() );
//	gl::drawCoordinateFrame();
  
	gl::popMatrices();
    
    gl::disableDepthRead();
    gl::disableDepthWrite();
    
	gl::setMatricesWindow( getWindowSize() );

	ciXtractReceiver::drawData( mFeature, Rectf( 15, getWindowHeight() - 150, 255, getWindowHeight() - 35 ) );
	
	gl::draw( mFeatureSurf );

    mParams->draw();
}
Exemplo n.º 15
0
void GeometryShaderApp::draw()
{
	// clear out the window 
	gl::clear( Color(0.95f, 0.95f, 0.95f) );

	// bind the shader and send the mesh to the GPU
	if(mShader && mVboMesh) {
		mShader.bind();
		mShader.uniform( "WIN_SCALE", Vec2f( getWindowSize() ) ); // casting to Vec2f is mandatory!
		mShader.uniform( "MITER_LIMIT", mLimit );
		mShader.uniform( "THICKNESS", mThickness );
		
		if(mTexture) {
			gl::enableAlphaBlending();
			gl::color( Color::white() );
			mTexture.enableAndBind();
		}
		else
			gl::color( Color::black() );

		gl::draw( mVboMesh );

		if(mTexture) {
			mTexture.unbind();
			gl::disableAlphaBlending();
		}

		if(mDrawWireframe) {
			gl::color( Color::black() );
			gl::enableWireframe();
			gl::draw( mVboMesh );
			gl::disableWireframe();
		}

		mShader.unbind();
	}

	// draw all points as red circles
	gl::color( Color(1, 0, 0) );

	std::vector<Vec2f>::const_iterator itr;
	for(itr=mPoints.begin();itr!=mPoints.end();++itr)
		gl::drawSolidCircle( *itr, mRadius );

	if( ! mPoints.empty() )
		gl::drawStrokedCircle( mPoints.back(), mRadius + 2.0f );

	// draw help
	if(mHelpTexture) {
		gl::color( Color::white() );
		gl::enableAlphaBlending();
		gl::draw( mHelpTexture );
		gl::disableAlphaBlending();
	}
}
void pinch_tap_sampleApp::draw()
{
    gl::clear(Color::black());
    
    gl::setMatricesWindowPersp(getWindowSize(), 60, 1, 2000);
    
    mRectTex.enableAndBind();
    for(vector<TouchRect*>::reverse_iterator it = mRects.rbegin(); it != mRects.rend(); ++it)
        (*it)->draw();
    mRectTex.unbind();
}
Exemplo n.º 17
0
void TutorialApp::draw()
{	
	gl::clear( Color( 0, 0, 0 ), true );
	
	mImage.enableAndBind();
	gl::draw( mImage, getWindowBounds() );
	
	glDisable( GL_TEXTURE_2D );
	glColor3f( 1, 1, 1 );
	mParticleController.draw();
}
Exemplo n.º 18
0
void godComplexApp::draw()
{
	
	gl::enableDepthRead();
	gl::enableDepthWrite();
	gl::enableAlphaBlending();
	
	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) );
	gl::setMatrices( mMayaCam.getCamera());
    
    
    
	if(drawWater == true){
		if(mWaterModule != NULL){
			gl::pushMatrices();
			mWaterModule->draw(0);
			gl::popMatrices();
		}
	}
    
    
    
	if(drawMesh == true){
		gl::pushMatrices();
		myImage.enableAndBind();
        //      gl::rotate( mArcball.getQuat() ); //NOTE: for debugging
		gl::scale(Vec3f(0.035,0.035,0.035));
		glLineWidth(0.2f);
		gl::enableWireframe();
		gl::translate(Vec3f(280.0, 0.0, -180.0));
		gl::rotate(Vec3f(-10.0, -10.0, 0.0));
		gl::draw(mVbo);
		gl::disableWireframe();
		myImage.unbind();
		gl::popMatrices();
    }
	
	
	gl::pushMatrices();
	mFlowField->draw();
	gl::popMatrices();
	
    
	
	/*
     glPushMatrix();
     glColor4f(1.0, 0.0, 0.0, 1.0);
     gl::drawSphere(Vec3f(userIncr1, userIncr2, userIncr3), 30.0, 12.0);
     glPopMatrix();
     */
}
Exemplo n.º 19
0
void TutorialApp::draw()
{	
	gl::clear( Color( 0, 0, 0 ), true );
	
	if( mDrawImage ){
		mTexture.enableAndBind();
		gl::draw( mTexture, getWindowBounds() );
	}
	
	if( mDrawParticles ){
		glDisable( GL_TEXTURE_2D );
		mParticleController.draw();
	}
}
Exemplo n.º 20
0
void BouncingBallsApp::draw()
{
	gl::clear(); 
	gl::enableAdditiveBlending();

	if(mTexture) mTexture.enableAndBind();

	std::vector<BallRef>::iterator itr;
	for(itr=mBalls.begin();itr!=mBalls.end();++itr)
		(*itr)->draw( mMesh, mUseMotionBlur );

	if(mTexture) mTexture.unbind();

	gl::disableAlphaBlending();
}
Exemplo n.º 21
0
void MandelbrotGLSLApp::setup()
{
	mBrotShader		= gl::GlslProg( loadResource( RES_VERT_GLSL ), loadResource( RES_FRAG_GLSL ) );
	mColorsTexture	= gl::Texture( loadImage( loadResource( RES_COLORS_PNG ) ) );
	mColorsTexture.enableAndBind();
	
	mCenter			= Vec2f( 0.7f, 0.0f );
	mScale			= 2.2f;
	
	// WARNING
	// Setting mIter too high will cause your computer to lock up.
	// For example, I tried 100000000 iterations. That was a stupid idea.
	// After five minutes of blowing air into my laptop, I gave up and shut
	// it down. Even 10000 will cause a noticeable pause.
	mIter			= 1500;
}
Exemplo n.º 22
0
void chapter3App::draw()
{
	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) ); 
        
    if(mDrawImage)
    {
        mColorTexture.enableAndBind();
        gl::draw( mColorTexture, getWindowBounds());
    }
    
    if ( mDrawParticles )
    {
        glDisable(GL_TEXTURE_2D);
        mParticleController.draw();
    }
}
Exemplo n.º 23
0
void QuaternionAccumApp::drawPlane()
{
	// draw the plane
	gl::color( Color( 1, 1, 1 ) );
	mPlaneTexture.enableAndBind();
	glBegin( GL_QUADS );
		glTexCoord2f( 0, 0 );
		glVertex3f( -10.0f, 0.0f, -10.0f );
		glTexCoord2f( 1, 0 );
		glVertex3f( 10.0f, 0.0f, -10.0f );
		glTexCoord2f( 1, 1 );
		glVertex3f( 10.0f, 0.0f, 10.0f );
		glTexCoord2f( 0, 1 );
		glVertex3f( -10.0f, 0.0f, 10.0f );
	glEnd();
	mPlaneTexture.disable();
}
Exemplo n.º 24
0
void TutorialApp::draw()
{	
	gl::clear( Color( 0, 0, 0 ), true );
	
	if( mDrawImage ){
		mTexture.enableAndBind();
		gl::draw( mTexture, getWindowBounds() );
	}
	
	if( mDrawParticles ){
		glDisable( GL_TEXTURE_2D );
		mParticleController.draw();
	}
	
	if( mSaveFrames ){
		writeImage( getHomeDirectory() + "image_" + toString( getElapsedFrames() ) + ".png", copyWindowSurface() );
	}
}
Exemplo n.º 25
0
void CatMemeMakerApp::draw()
{
	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) ); 
	gl::enableAlphaBlending();

	//Check that the url fetch was successful
	if (mImage) {
		//Draw the Cat!
		mImage.enableAndBind();
		gl::draw( mImage, getWindowBounds() );
	}

	//If we are on the second line, write what we used to have for the first line up top
	if (mFirstLine) {
		gl::draw(mFirstLine,Vec2f( getWindowSize().x/2 - mFirstLine.getWidth()/2, 10 ));
	}

	//Render the texture with the message
	TextLayout simple;

	std::string normalFont( "Arial" );

	simple.setFont( Font(normalFont,48) );
	simple.setColor( Color( 1, 1, 1 ) );

	//White looked bad on the second line... so change to black if on second line
	if (mFirstLine) {
		simple.setColor( Color( 255, 255, 255 ) );
	}
	simple.addCenteredLine(mMessage.str());

	mTexture = gl::Texture( simple.render( true , false ) );

	//Draw the message, centered!
	if (mFirstLine) {
		gl::draw(mTexture,Vec2f( getWindowSize().x/2 - mTexture.getWidth()/2, getWindowSize().y -50));
	}
	else {
		gl::draw(mTexture,Vec2f( getWindowSize().x/2 - mTexture.getWidth()/2, 10 ));
	}
}
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();
}
void wellingtonModelApp::draw()
{
    
    gl::enableDepthRead();
    gl::enableDepthWrite();
    gl::enableAlphaBlending();
    
    // clear out the window with black
	gl::clear( Color( 0, 0, 0 ) );
    
    /*
     if(mWaterModule != NULL){
     gl::pushMatrices();
     mWaterModule->draw();
     gl::popMatrices();
     }
     */
    
    
//    /*
    gl::setMatrices( mMayaCam.getCamera());
    
    gl::pushMatrices();
    myImage.enableAndBind();
    gl::rotate( mArcball.getQuat() );
    gl::scale(Vec3f(0.035,0.035,0.035));
    glLineWidth(0.3f);
    gl::enableWireframe();
    gl::rotate(Vec3f(50.0, -20.0, 0.0));
    gl::draw(mVbo);
    myImage.unbind();
    gl::popMatrices();
     
//     */
    
 
    
}
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();
}
Exemplo n.º 29
0
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");
}
Exemplo n.º 30
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();
}