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();
}
Ejemplo n.º 2
0
void GpGpuApp::mouseDrag( MouseEvent event )
{
	if ( event.isControlDown() ) {
		mArcball.mouseDrag( event.getPos() );
	} else {
		Vec2f pos		= Vec2f( event.getPos() );
		mMouseVelocity	= pos - mMouse;
		mMouse			= pos;
	}
}
Ejemplo n.º 3
0
void GpGpuApp::mouseDown( MouseEvent event )
{
	if ( event.isControlDown() ) {
		mArcball.mouseDown( event.getPos() );
	} else {
		mMouseVelocity	= Vec2f::zero();
		mMouse			= Vec2f( event.getPos() );
		mMouseDown		= true;
	}
}
void PaintingBeingsApp::resetCamera()
{
	float eyeZ = static_cast<float>(_rectangleTextutre.getWidth()) * 2.5f;

	if (_showImageBeing)
		eyeZ = static_cast<float>(_image.getMiniatureSize()) * 2.5f;

	float radiusArcBall = static_cast<float>(getWindowHeight() * 0.5f);

	float fieldOfView = 75.0f;
	float nearCamera = 0.1f;
	float farCamera = 1000000.0f;
	_camera = CameraPersp(getWindowWidth(), getWindowHeight(), fieldOfView, nearCamera, farCamera);

	_camera.lookAt(Vec3f(0.0f, 0.0f, eyeZ), Vec3f::zero());
	_arcball = Arcball(getWindowSize());
	_arcball.setRadius(radiusArcBall);
}
void PaintingBeingsApp::setup()
{	
	setStop();

	// Setup des paramètres de OpenGL
	glShadeModel(GL_SMOOTH);
	gl::enable(GL_POLYGON_SMOOTH);
	glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
	gl::enableAlphaBlending();
	gl::enableDepthRead();
	gl::enableDepthWrite();

	// Setup Capture webcam
	_capture = Capture(640, 480);
	_capture.start();

	// Setup camera
	float fieldOfView = 75.0f;
	float nearCamera = 0.1f;
	float farCamera = 1000000.0f;
	_camera = CameraPersp(getWindowWidth(), getWindowHeight(), fieldOfView, nearCamera, farCamera);
	_camera.lookAt(Vec3f(0.0f, 0.0f, 50.0f), Vec3f::zero());

	// Setup arcball (camera rotation)
	float radiusArcBall = static_cast<float>(getWindowHeight() * 0.5f);
	_arcball = Arcball(getWindowSize());
	_arcball.setRadius(radiusArcBall);


	// Génération de la population d'ImageBeing
	_imageBeing = ImageBeing();

	_rectangleAlgoGen.set(-75.0f, 25.0f, -25.0f, -25.0f);
	_rectangleTextutre.set(25.0f, 25.0f, 75.0f, -25.0f);


	// Setup de l'interface
	_params = params::InterfaceGl("Options", Vec2i(200, 400));
	updateInterface(false);
}
Ejemplo n.º 6
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();
	}
}
Ejemplo n.º 7
0
void GpGpuApp::setup()
{
	// Load shaders
	try {
		mGlslProgDraw = gl::GlslProg::create( loadResource( RES_GLSL_DRAW_VERT ), loadResource( RES_GLSL_DRAW_FRAG ) );
	} catch ( gl::GlslProgCompileExc ex ) {
		console() << ex.what() << "\n";
		quit();
	}
	
	try {
		mGlslProgGpGpu0 = gl::GlslProg::create( loadResource( RES_GLSL_GPGPU_VERT ), loadResource( RES_GLSL_GPGPU0_FRAG ) );
	} catch ( gl::GlslProgCompileExc ex ) {
		console() << ex.what() << "\n";
		quit();
	}
	
	try {
		mGlslProgGpGpu1 = gl::GlslProg::create( loadResource( RES_GLSL_GPGPU_VERT ), loadResource( RES_GLSL_GPGPU1_FRAG ) );
	} catch ( gl::GlslProgCompileExc ex ) {
		console() << ex.what() << "\n";
		quit();
	}
	
	// Define all properties
	mArcball					= Arcball( getWindowSize() );
	mBrushSize					= 0.1f;
	mCamera						= CameraPersp( getWindowWidth(), getWindowHeight(), 60.0f, 1.0f, 100000.0f );
	mEyePoint					= Vec3f( 0.0f, 20.0f, 256.0f );
	mFullScreen					= isFullScreen();
	mFullScreenPrev				= mFullScreen;
	mLightAmbient				= ColorAf::gray( 0.1f );
	mLightAttenuationConstant	= 0.1f;
	mLightAttenuationLinear		= 0.01f;
	mLightAttenuationQuadratic	= 0.001f;
	mLightDiffuse				= ColorAf( 0.9f, 0.3f, 0.667f );
	mLightPosition				= Vec3f( 11.38f, -1.39f, 59.74f );
	mLightSpecular				= ColorAf::white();
	mLightShine					= 1.0f;
	mMaterialAmbient			= 1.0f;
	mMaterialDiffuse			= 1.0f;
	mMaterialEmissive			= 0.0f;
	mMaterialSpecular			= 1.0f;
	mMesh						= gl::VboMesh::create( MeshHelper::createCube() );
	mMouseDown					= false;
	mMouse						= Vec2f::zero();
	mMouseVelocity				= Vec2f::zero();
	mParams						= params::InterfaceGl::create( "Params", Vec2i( 250, 400 ) );
	mSize						= Vec2i( 512, 512 );
	mSizePrev					= Vec2i::zero();
	mTextureBrush				= gl::Texture::create( loadImage( loadResource( RES_PNG_BRUSH ) ) );
	
	// Set up arcball
	mArcball.setRadius( (float)getWindowHeight() * 0.5f );
	
	// Set up parameters
	mParams->addParam( "Frame rate",		&mFrameRate,					"", true );
	mParams->addParam( "Full screen",		&mFullScreen,					"key=f" );
	mParams->addButton( "Quit",				bind( &GpGpuApp::quit, this ),	"key=q" );
	
	mParams->addSeparator( "" );
	mParams->addParam( "Brush size",		&mBrushSize,					"min=0.0 max=1.0 step=0.001" );
	mParams->addParam( "Size X",			&mSize.x,						"min=1 max=1024 step=1" );
	mParams->addParam( "Size Y",			&mSize.y,						"min=1 max=1024 step=1" );
	
	mParams->addSeparator( "" );
	mParams->addParam( "Light ambient",		&mLightAmbient );
	mParams->addParam( "Light att const",	&mLightAttenuationConstant,		"min=0.0 max=1.0 step=0.001" );
	mParams->addParam( "Light att line",	&mLightAttenuationLinear,		"min=0.0 max=1.0 step=0.0001" );
	mParams->addParam( "Light att quad",	&mLightAttenuationQuadratic,	"min=0.0 max=1.0 step=0.00001" );
	mParams->addParam( "Light diffuse",		&mLightDiffuse );
	mParams->addParam( "Light position",	&mLightPosition );
	mParams->addParam( "Light specular",	&mLightSpecular );
	mParams->addParam( "Light shine",		&mLightShine,					"min=0.0 max=100000.0 step=1.0" );
	
	mParams->addSeparator( "" );
	mParams->addParam( "Material ambient",	&mMaterialAmbient,				"min=0.0 max=1.0 step=0.001" );
	mParams->addParam( "Material diffuse",	&mMaterialDiffuse,				"min=0.0 max=1.0 step=0.001" );
	mParams->addParam( "Material emissive",	&mMaterialEmissive,				"min=0.0 max=1.0 step=0.001" );
	mParams->addParam( "Material specular",	&mMaterialSpecular,				"min=0.0 max=1.0 step=0.001" );
}
void PaintingBeingsApp::mouseDrag(MouseEvent event)
{
	_arcball.mouseDrag(event.getPos());
}
Ejemplo n.º 9
0
void VboMeshSampleApp::setup()
{
	// Setting an unrealistically high frame rate effectively
	// disables frame rate limiting
	setFrameRate( 10000.0f );
	setWindowSize( 800, 600 );

	// Set up OpenGL to work with default lighting
	glShadeModel( GL_SMOOTH );
	gl::enable( GL_POLYGON_SMOOTH );
	glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST );
	gl::enable( GL_NORMALIZE );
	gl::enableAlphaBlending();
	gl::enableDepthRead();
	gl::enableDepthWrite();

	// Load the texture map
	mTexture = gl::Texture( loadImage( loadResource( RES_TEXTURE ) ) );

	// Define properties
	mFrameRate			= 0.0f;
	mFullScreen			= false;
	mLightEnabled		= true;
	mMeshIndex			= 0;
	mNumSegments		= 48;
	mNumSegmentsPrev	= mNumSegments;
	mScale				= Vec3f::one();
	mTextureEnabled		= true;
	mWireframe			= false;
	
	// Set up the arcball
	mArcball = Arcball( getWindowSize() );
	mArcball.setRadius( (float)getWindowHeight() * 0.5f );
	
	// Set up the camera
	mCamera = CameraPersp( getWindowWidth(), getWindowHeight(), 60.0f, 0.0001f, 10.0f );
	mCamera.lookAt( Vec3f( 0.0f, 0.0f, -5.0f ), Vec3f::zero() );

	// Set up the light
	mLight = new gl::Light( gl::Light::DIRECTIONAL, 0 );
	mLight->setAmbient( ColorAf::white() );
	mLight->setDiffuse( ColorAf::white() );
	mLight->setDirection( Vec3f::one() );
	mLight->setPosition( Vec3f::one() * -1.0f );
	mLight->setSpecular( ColorAf::white() );
	mLight->enable();

	// Define the mesh titles for the params GUI
	mMeshTitles.push_back( "Cube" );
	mMeshTitles.push_back( "Sphere" );
	mMeshTitles.push_back( "Cylinder" );
	mMeshTitles.push_back( "Cone" );
	mMeshTitles.push_back( "Circle" );
	mMeshTitles.push_back( "Square" );
	mMeshTitles.push_back( "Ring" );
	mMeshTitles.push_back( "Custom" );

	// Set up the params GUI
	mParams = params::InterfaceGl( "Params", Vec2i( 200, 320 ) );
	mParams.addParam( "Frame rate",		&mFrameRate,									"", true									);
	mParams.addSeparator();
	mParams.addParam( "Enable light",	&mLightEnabled,									"key=l"										);
	mParams.addParam( "Enable texture",	&mTextureEnabled,								"key=t"										);
	mParams.addParam( "Mesh type",		mMeshTitles, &mMeshIndex,						"keyDecr=m keyIncr=M"						);
	mParams.addParam( "Scale",			&mScale																						);
	mParams.addParam( "Segments",		&mNumSegments,									"keyDecr=s keyIncr=S min=3 max=1024 step=1"	);
	mParams.addParam( "Wireframe",		&mWireframe,									"key=w"										);
	mParams.addSeparator();
	mParams.addParam( "Full screen",	&mFullScreen,									"key=f"										);
	mParams.addButton( "Screen shot",	bind( &VboMeshSampleApp::screenShot, this ),	"key=space"									);
	mParams.addButton( "Quit",			bind( &VboMeshSampleApp::quit, this ),			"key=q"										);

	// Generate meshes
	createMeshes();
}
Ejemplo n.º 10
0
void VboMeshSampleApp::mouseDrag( MouseEvent event )
{
	// Rotate with arcball
	mArcball.mouseDrag( event.getPos() );
}
Ejemplo n.º 11
0
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();
}