void PaintingBeingsApp::draw()
{
	gl::clear(ColorAf::gray(0.6f));

	gl::setViewport(getWindowBounds());
	gl::setMatrices(_camera);

	glMultMatrixf(_arcball.getQuat());

	if (_showWireFrame)
		gl::enableWireframe();
	else
		gl::disableWireframe();

	if (_launchAlgoGen)
	{
		if (!_showImageBeing)
		{
			_image.getTexture().enableAndBind();
			gl::draw(_image.getTexture(), _rectangleTextutre);
			_image.getTexture().unbind();

			gl::Texture textureAlgoGen = _algoGen.getBestImage();
			textureAlgoGen.enableAndBind();
			gl::draw(textureAlgoGen, _rectangleAlgoGen);
			textureAlgoGen.unbind();
		}
		else
		{
			_imageBeing.draw(_algoGen.getBestImage());
		}
	}	

	_params.draw();
}
Esempio n. 2
0
void GpGpuApp::draw()
{
	// We're going to draw new data onto the "ping" FBO,
	// using the "pong" FBO's textures as input
	size_t pong = ( mFboIndex + 1 ) % 2;
	
	// Set up OpenGL for data
	gl::disableDepthRead();
	gl::disableDepthWrite();
	gl::setViewport( mFbo[ mFboIndex ].getBounds() );
	gl::color( ColorAf::white() );
	
	// Draw any new input onto the acceleration texture
	mFbo[ pong ].bindFramebuffer();
	glDrawBuffer( GL_COLOR_ATTACHMENT2 );
	if ( mMouseDown ) {
		Vec2f fboSize	= Vec2f( mFbo[ mFboIndex ].getSize() );
		Vec2f winSize	= Vec2f( app::getWindowSize() );
		
		gl::setMatricesWindow( fboSize, true );
		
		Vec2f brushSize	= Vec2f::one() * mBrushSize * fboSize;
		Vec2f pos		= ( mMouse / winSize );
		pos.y			= 1.0f - pos.y;
		pos				*= fboSize;
		
		mGlslProgGpGpu0->bind();
		mGlslProgGpGpu0->uniform( "color", ColorAf( mMouseVelocity.x, 0.0f, 1.0f - mMouseVelocity.y, 1.0f ) );
		mGlslProgGpGpu0->uniform( "tex", 0 );
		
		gl::enable( GL_TEXTURE_2D );
		mTextureBrush->bind();
		gl::drawSolidRect( Rectf( pos - brushSize, pos + brushSize ) );
		mTextureBrush->unbind();
		gl::disable( GL_TEXTURE_2D );
		
		mGlslProgGpGpu0->unbind();
	}
	mFbo[ pong ].unbindFramebuffer();
	
	// Now let's do an update pass in GLSL
	mFbo[ mFboIndex ].bindFramebuffer();
	gl::setMatricesWindow( mFbo[ mFboIndex ].getSize(), false );
	
	// Bind the "pong" textures to use as input data
	for ( int32_t i = 0; i < 3; ++i ) {
		mFbo[ pong ].bindTexture( i, i );
	}
	
	// Set up shader to read data textures
	mGlslProgGpGpu1->bind();
	mGlslProgGpGpu1->uniform( "offsets",		0 );
	mGlslProgGpGpu1->uniform( "velocities",		1 );
	mGlslProgGpGpu1->uniform( "acceleration",	2 );
	
	// Draw a rect to process data
	glDrawBuffers( 3, kColorAttachments );
	gl::drawSolidRect( mFbo[ pong ].getBounds() );
	
	// Unbind everything
	mFbo[ pong ].unbindTexture();
	mGlslProgGpGpu1->unbind();
	mFbo[ mFboIndex ].unbindFramebuffer();
	
	// Swap FBOs
	mFboIndex = pong;
	
	/////////////////////////////////
	
	// Make sure we have data to work with before we draw geometry
	if ( mFbo[ mFboIndex ] &&
		mFbo[ mFboIndex ].getTexture( 0 ) &&
		mFbo[ mFboIndex ].getTexture( 1 ) ) {
		
		// Set up window for 3D drawing
		gl::clear( Colorf( 0.5f, 0.45f, 0.4f ) );
		gl::setViewport( getWindowBounds() );
		gl::setMatrices( mCamera );
		gl::enableDepthRead();
		gl::enableDepthWrite();
		gl::multModelView( mArcball.getQuat() );
		gl::color( ColorAf::black() );
		
		// Set up shader to render scene
		mGlslProgDraw->bind();
		mGlslProgDraw->uniform( "Ax",			mLightAmbient );
		mGlslProgDraw->uniform( "Ac",			mLightAttenuationConstant );
		mGlslProgDraw->uniform( "Al",			mLightAttenuationLinear );
		mGlslProgDraw->uniform( "Aq",			mLightAttenuationQuadratic );
		mGlslProgDraw->uniform( "Dx",			mLightDiffuse );
		mGlslProgDraw->uniform( "eyePoint",		mEyePoint );
		mGlslProgDraw->uniform( "Ka",			mMaterialAmbient );
		mGlslProgDraw->uniform( "Kd",			mMaterialDiffuse );
		mGlslProgDraw->uniform( "Ke",			mMaterialEmissive );
		mGlslProgDraw->uniform( "Ks",			mMaterialSpecular );
		mGlslProgDraw->uniform( "lightPos",		mLightPosition );
		mGlslProgDraw->uniform( "n",			mLightShine );
		mGlslProgDraw->uniform( "offsets",		0 );
		mGlslProgDraw->uniform( "projection",	mCamera.getProjectionMatrix() );
		mGlslProgDraw->uniform( "size",			Vec2f( mSize ) );
		mGlslProgDraw->uniform( "Sx",			mLightSpecular );
		mGlslProgDraw->uniform( "t",			(float)getElapsedSeconds() );
		
		// Bind textures to use as input data
		for ( int32_t i = 0; i <= 2; ++i ) {
			mFbo[ mFboIndex ].bindTexture( i, i );
		}
		
		// Draw instanced
		drawInstanced( mMesh, mSize.x * mSize.y );
		
		// Finished drawing
		mFbo[ mFboIndex ].unbindTexture();
		mGlslProgDraw->unbind();
		
		// Draw textures so we can see what's going on under the hood
		gl::setMatricesWindow( getWindowSize() );
		gl::disableDepthRead();
		gl::disableDepthWrite();
		gl::color( ColorAf::white() );
		gl::pushMatrices();
		
		float x = 20.0f;
		float y = 440.0f;
		
		float width = 64.0f;
		Area srcArea( Vec2i::zero(), mSize );
		Rectf destRect( x, y, x + width, y + width );
		
		gl::draw( mFbo[ 0 ].getTexture( 0 ), srcArea, destRect );
		destRect.x1 += width;
		destRect.x2 += width;
		gl::draw( mFbo[ 1 ].getTexture( 0 ), srcArea, destRect );
		
		destRect.y1 += width;
		destRect.y2 += width;
		destRect.x1 = x;
		destRect.x2 = x + width;
		gl::draw( mFbo[ 0 ].getTexture( 1 ), srcArea, destRect );
		destRect.x1 += width;
		destRect.x2 += width;
		gl::draw( mFbo[ 1 ].getTexture( 1 ), srcArea, destRect );
		
		destRect.y1 += width;
		destRect.y2 += width;
		destRect.x1 = x;
		destRect.x2 = x + width;
		gl::draw( mFbo[ 0 ].getTexture( 2 ), srcArea, destRect );
		destRect.x1 += width;
		destRect.x2 += width;
		gl::draw( mFbo[ 1 ].getTexture( 2 ), srcArea, destRect );
		gl::popMatrices();
	}
	
	// Draw parameters
	if ( getElapsedFrames() > 1 ) { // This condition prevents a memory leak
		mParams->draw();
	}
}
void VboMeshSampleApp::draw()
{
	// Set up window
	gl::setViewport( getWindowBounds() );
	gl::setMatrices( mCamera );
	gl::clear( ColorAf::gray( 0.6f ) );

	// Use arcball to rotate model view
	glMultMatrixf( mArcball.getQuat() );

	// Enabled lighting, texture mapping, wireframe
	if ( mLightEnabled ) {
		gl::enable( GL_LIGHTING );
	}
	if ( mTextureEnabled && mTexture ) {
		gl::enable( GL_TEXTURE_2D );
		mTexture.bind();
	}
	if ( mWireframe ) {
		gl::enableWireframe();
	}

	// Apply scale
	gl::pushMatrices();
	gl::scale( mScale );
	
	// Draw selected mesh
	switch ( (MeshType)mMeshIndex ) {
	case MESH_TYPE_CIRCLE:
		gl::draw( mCircle );
		break;
	case MESH_TYPE_CONE:
		gl::draw( mCone );
		break;
	case MESH_TYPE_CUBE:
		gl::draw( mCube );
		break;
	case MESH_TYPE_CUSTOM:
		gl::draw( mCustom );
		break;
	case MESH_TYPE_CYLINDER:
		gl::draw( mCylinder );
		break;
	case MESH_TYPE_RING:
		gl::draw( mRing );
		break;
	case MESH_TYPE_SPHERE:
		gl::draw( mSphere );
		break;
	case MESH_TYPE_SQUARE:
		gl::draw( mSquare );
		break;
	}
	
	// End scale
	gl::popMatrices();

	// Disable wireframe, texture mapping, lighting
	if ( mWireframe ) {
		gl::disableWireframe();
	}
	if ( mTextureEnabled && mTexture ) {
		mTexture.unbind();
		gl::disable( GL_TEXTURE_2D );
	}
	if ( mLightEnabled ) {
		gl::disable( GL_LIGHTING );
	}

	// Draw params GUI
	mParams.draw();
}