void RepulsionApp::setFboVelocities( gl::Fbo &fbo )
{
	Surface32f vel( fbo.getTexture() );
	Surface32f::Iter it = vel.getIter();
	while( it.line() ){
		while( it.pixel() ){
			Vec3f r = Rand::randVec3f() * 0.1f;
			it.r() = 0.0f;//r.x;
			it.g() = 0.0f;//r.y;
			it.b() = 0.0f;//r.z;
			it.a() = 0.0f;
		}
	}
	
	gl::Texture velTexture( vel );
	velTexture.bind();
	
	gl::setMatricesWindow( mFboSize, false );
	gl::setViewport( mFboBounds );
	
	fbo.bindFramebuffer();
	mVelInitShader.bind();
	mVelInitShader.uniform( "initTex", 0 );
	gl::drawSolidRect( mFboBounds );
	mVelInitShader.unbind();
	fbo.unbindFramebuffer();
}
void CatalogApp::setFboPositions( gl::Fbo &fbo )
{
	int numBrightStars = mBrightStars.size();

	int index = 0;
	
	Surface32f posSurface( fbo.getTexture() );
	Surface32f::Iter it = posSurface.getIter();
	while( it.line() ){
		while( it.pixel() ){
			Vec3f pos = Vec3f( 1000000.0f, 0.0f, 0.0f );
			float col = 0.4f;
			float rad = 0.0f;
			if( index < numBrightStars ){
				pos = mBrightStars[index]->mPos;
				col = mBrightStars[index]->mColor;
				rad = floor( constrain( ( ( 6.0f - ( mBrightStars[index]->mAbsoluteMag ) )/6.0f ), 0.3f, 1.0f ) * 3.0f * 1000 );
			}
			it.r() = pos.x;
			it.g() = pos.y;
			it.b() = pos.z;
			it.a() = rad + col;

			index ++;
		}
	}

	gl::Texture posTexture( posSurface );
	fbo.bindFramebuffer();
	gl::setMatricesWindow( fbo.getSize(), false );
	gl::setViewport( fbo.getBounds() );
	gl::clear( ColorA( 0, 0, 0, 0 ), true );
	gl::draw( posTexture );
	fbo.unbindFramebuffer();
}
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();
}