Ejemplo n.º 1
0
// Set up
void UiApp::setup()
{
	glShadeModel( GL_FLAT );
	
	// Set up camera
	mCamera = CameraPersp( getWindowWidth(), getWindowHeight(), 45.0f, 0.01f, 1000.0f );
	mOffset = Vec3f( 240.0f, -480.0f, 0.0f );
	
	// Start device
	mLeap = Device::create();
	mLeap->addCallback( &UiApp::onFrame, this );
	
	// Load cursor textures
	for ( size_t i = 0; i < 3; ++i ) {
		switch ( (CursorType)i ) {
			case CursorType::GRAB:
				mTexture[ i ] = gl::Texture( loadImage( loadResource( RES_TEX_GRAB ) ) );
				break;
			case CursorType::HAND:
				mTexture[ i ] = gl::Texture( loadImage( loadResource( RES_TEX_HAND ) ) );
				break;
			case CursorType::TOUCH:
				mTexture[ i ] = gl::Texture( loadImage( loadResource( RES_TEX_TOUCH ) ) );
				break;
			case NONE:
				break;
		}
		mTexture[ i ].setFlipped( true );
		mTexture[ i ].setMagFilter( GL_NEAREST );
		mTexture[ i ].setMinFilter( GL_NEAREST );
	}
	
	// Initialize cursor
	mCursorType				= CursorType::NONE;
	mCursorPosition			= Vec3f::zero();
	mCursorPositionTarget	= Vec3f::zero();
	
	// Load UI textures
	mButton[ 0 ]	= gl::Texture( loadImage( loadResource( RES_TEX_BUTTON_OFF ) ) );
	mButton[ 1 ]	= gl::Texture( loadImage( loadResource( RES_TEX_BUTTON_ON ) ) );
	mSlider			= gl::Texture( loadImage( loadResource( RES_TEX_SLIDER ) ) );
	mTrack			= gl::Texture( loadImage( loadResource( RES_TEX_TRACK ) ) );

	// Flip textures
	mButton[ 0 ].setFlipped( true );
	mButton[ 1 ].setFlipped( true );
	mSlider.setFlipped( true );
	mTrack.setFlipped( true );
	
	// Disable anti-aliasing
	mButton[ 0 ].setMagFilter( GL_NEAREST );
	mButton[ 0 ].setMinFilter( GL_NEAREST );
	mButton[ 1 ].setMagFilter( GL_NEAREST );
	mButton[ 1 ].setMinFilter( GL_NEAREST );
	mSlider.setMagFilter( GL_NEAREST );
	mSlider.setMinFilter( GL_NEAREST );
	mTrack.setMagFilter( GL_NEAREST );
	mTrack.setMinFilter( GL_NEAREST );
	
	// Initialize buttons
	Vec3f position( -120.0f, 950.0f, 0.0f );
	for ( size_t i = 0; i < 3; ++i, position.x += 320.0f ) {
		mButtonPosition[ i ]	= position;
		mButtonState[ i ]		= false;
	}
	
	// Initialize sliider
	mTrackPosition		= Vec3f( 0.0f, 700.0f, 0.0f );
	mSliderPosition		= mTrackPosition;
	mSliderPosition.y	-= 45.0f;
	
	// Params
	mFrameRate	= 0.0f;
	mFullScreen	= false;
	mParams = params::InterfaceGl( "Params", Vec2i( 200, 105 ) );
	mParams.addParam( "Frame rate",		&mFrameRate,						"", true );
	mParams.addParam( "Full screen",	&mFullScreen,						"key=f"		);
	mParams.addButton( "Screen shot",	bind( &UiApp::screenShot, this ),	"key=space" );
	mParams.addButton( "Quit",			bind( &UiApp::quit, this ),			"key=q" );
}
Ejemplo n.º 2
0
// Set up
void UiApp::setup()
{
	glShadeModel( GL_FLAT );
		
	// Start device
	mDevice 		= Device::create();
	mDevice->connectEventHandler( &UiApp::onFrame, this );
	
	// Load cursor textures
	for ( size_t i = 0; i < 3; ++i ) {
		switch ( (CursorType)i ) {
			case CursorType::GRAB:
				mTexture[ i ] = gl::Texture( loadImage( loadResource( RES_TEX_GRAB ) ) );
				break;
			case CursorType::HAND:
				mTexture[ i ] = gl::Texture( loadImage( loadResource( RES_TEX_HAND ) ) );
				break;
			case CursorType::TOUCH:
				mTexture[ i ] = gl::Texture( loadImage( loadResource( RES_TEX_TOUCH ) ) );
				break;
			case NONE:
				break;
		}
		mTexture[ i ].setMagFilter( GL_NEAREST );
		mTexture[ i ].setMinFilter( GL_NEAREST );
	}
	
	// Initialize cursor
	mCursorType				= CursorType::NONE;
	mCursorPosition			= Vec2f::zero();
	mCursorPositionTarget	= Vec2f::zero();
	mFingerTipPosition		= Vec2i::zero();
	
	// Load UI textures
	mButton[ 0 ]	= gl::Texture( loadImage( loadResource( RES_TEX_BUTTON_OFF ) ) );
	mButton[ 1 ]	= gl::Texture( loadImage( loadResource( RES_TEX_BUTTON_ON ) ) );
	mSlider			= gl::Texture( loadImage( loadResource( RES_TEX_SLIDER ) ) );
	mTrack			= gl::Texture( loadImage( loadResource( RES_TEX_TRACK ) ) );
	
	// Disable anti-aliasing
	mButton[ 0 ].setMagFilter( GL_NEAREST );
	mButton[ 0 ].setMinFilter( GL_NEAREST );
	mButton[ 1 ].setMagFilter( GL_NEAREST );
	mButton[ 1 ].setMinFilter( GL_NEAREST );
	mSlider.setMagFilter( GL_NEAREST );
	mSlider.setMinFilter( GL_NEAREST );
	mTrack.setMagFilter( GL_NEAREST );
	mTrack.setMinFilter( GL_NEAREST );
	
	// Params
	mFrameRate	= 0.0f;
	mFullScreen	= false;
	mParams = params::InterfaceGl( "Params", Vec2i( 200, 105 ) );
	mParams.addParam( "Frame rate",		&mFrameRate,						"", true );
	mParams.addParam( "Full screen",	&mFullScreen,						"key=f"		);
	mParams.addButton( "Screen shot",	bind( &UiApp::screenShot, this ),	"key=space" );
	mParams.addButton( "Quit",			bind( &UiApp::quit, this ),			"key=q" );
	
	// Run resize to initialize layout
	resize();
}