void Screenport::SetUI( const Rectangle2I* clip )	
{
	if ( clip && clip->Area() > 1 ) {
		clipInUI2D = Rectangle2F( (float)clip->min.x, (float)clip->min.y, (float)clip->max.x, (float)clip->max.y );
	}
	else {
		clipInUI2D = Rectangle2F( 0, 0, UIWidth(), UIHeight() );
	}
	GLASSERT( clipInUI2D.IsValid() );
	GLASSERT( clipInUI2D.min.x >= 0 && clipInUI2D.max.x <= UIWidth() );
	GLASSERT( clipInUI2D.min.y >= 0 && clipInUI2D.max.y <= UIHeight() );

	Rectangle2F scissor;
	UIToWindow( clipInUI2D, &scissor );

	Rectangle2I clean;
	CleanScissor( scissor, &clean );
	GPUShader::SetScissor(  clean.min.x, clean.min.y, clean.Width(), clean.Height() );

	//view2D.SetIdentity();
	
	projection2D.SetIdentity();
	projection2D.SetOrtho( 0, screenWidth, screenHeight, 0, -1, 1 );
	GPUShader::SetOrthoTransform( (int)screenWidth, (int)screenHeight, Rotation()*90 );
	uiMode = true;
}
Exemple #2
0
void MapScene::ItemTapped(const gamui::UIItem* item)
{
	Vector2I sector = { 0, 0 };
	Vector2I v = data->destSector;
	CoreScript* cs = CoreScript::GetCore(v);
	CoreScript* homeCore = lumosChitBag->GetHomeCore();

	if (item == &okay) {
		data->destSector.Zero();
		lumosGame->PopScene();
	}
	else if (item == &gridTravel) {
		lumosGame->PopScene();
	}
	else if (item == &viewButton) {
		data->view = true;
		lumosGame->PopScene();
	}
	else if (item == &mapImage) {
		float x = 0, y = 0;
		gamui2D.GetRelativeTap(&x, &y);
		sector.x = int(x * float(NUM_SECTORS));
		sector.y = int(y * float(NUM_SECTORS));
		data->destSector = sector;
		DrawMap();
		EnableButtons();
	}
	else if (item == &mapImage2) {
		float x = 0, y = 0;
		gamui2D.GetRelativeTap(&x, &y);
		Rectangle2I b = MapBounds2();
		sector.x = b.min.x + int(x * float(b.Width()));
		sector.y = b.min.y + int(y * float(b.Height()));
		data->destSector = sector;
		DrawMap();
		EnableButtons();
	}
	else if (item == &warButton) {
		Team::Instance()->War(cs, homeCore, true, &lumosChitBag->GetSim()->GetCachedWeb());
		DrawMap();
		EnableButtons();
	}
	else if (item == &peaceButton) {
		int cost = Team::Instance()->Peace(cs, homeCore, false, &lumosChitBag->GetSim()->GetCachedWeb());
		Wallet* wallet = homeCore->ParentChit()->GetWallet();
		if (wallet->HasGold(cost)) {
			ReserveBank::Instance()->GetWallet()->Deposit(wallet, cost);
			Team::Instance()->Peace(cs, homeCore, true, &lumosChitBag->GetSim()->GetCachedWeb());
			DrawMap();
			EnableButtons();
		}
	}
}
Exemple #3
0
void KrOglTexture::SetTexture(	const KrRGBA* pixels, 
								const Rectangle2I& pixelCoords  )
{
	glBindTexture( GL_TEXTURE_2D, textureId );

	/* sigh. Still have to flip bytes. */
	int byteSize = pixelCoords.Width() * pixelCoords.Height() * 4;
	int colorSize = pixelCoords.Width() * pixelCoords.Height();

	U8* data = new U8[ byteSize ];
	
	GLASSERT( data  );
	if ( !data ) return;

	memcpy( data, pixels, byteSize );

	#ifdef KYRA_FLIP_COLORS
		U8* p = data;
		for ( int i=0; i<colorSize; ++i )
		{
			Swap( &p[0], &p[2] );
			p += 4;
		}
	#endif

	glTexSubImage2D(GL_TEXTURE_2D, 
					0,						// no mip mapping
					pixelCoords.min.x,		// coords on the texture
					pixelCoords.min.y,
					pixelCoords.Width(),	// coords on the source -- must be equal
					pixelCoords.Height(),
					GL_RGBA,				// format
					GL_UNSIGNED_BYTE,
					data );

	GLASSERT( glGetError() == GL_NO_ERROR );
	delete [] data;
}
void Screenport::SetPerspective( const grinliz::Rectangle2I* clip )
{
	uiMode = false;

	if ( clip && clip->Area() > 1 ) {
		clipInUI3D = Rectangle2F( (float)clip->min.x, (float)clip->min.y, (float)clip->max.x, (float)clip->max.y );
	}
	else {
		clipInUI3D = Rectangle2F( 0, 0, UIWidth(), UIHeight() );
	}
	GLASSERT( clipInUI3D.IsValid() );
	GLASSERT( clipInUI3D.min.x >= 0 && clipInUI3D.max.x <= UIWidth() );
	GLASSERT( clipInUI3D.min.y >= 0 && clipInUI3D.max.y <= UIHeight() );
	
	Rectangle2F scissor;
	UIToWindow( clipInUI3D,  &scissor );

	Rectangle2I clean;
	CleanScissor( scissor, &clean );
	GPUShader::SetScissor(  clean.min.x, clean.min.y, clean.Width(), clean.Height() );

	GLASSERT( uiMode == false );
	GLASSERT( EL_NEAR > 0.0f );
	GLASSERT( EL_FAR > EL_NEAR );

	frustum.zNear = EL_NEAR;
	frustum.zFar  = EL_FAR;

	// Convert from the FOV to the half angle.
	float theta = ToRadian( EL_FOV * 0.5f );
	float tanTheta = tanf( theta );
	float halfLongSide = tanTheta * frustum.zNear;

	// left, right, top, & bottom are on the near clipping
	// plane. (Not an obvious point to my mind.)

	// Also, the 3D camera applies the rotation.
	
	if ( Rotation() & 1 ) {
		float ratio = (float)clipInUI3D.Height() / (float)clipInUI3D.Width();
		
		// frustum is in original screen coordinates.
		frustum.top		=  halfLongSide;
		frustum.bottom	= -halfLongSide;
		
		frustum.left	= -ratio * halfLongSide;
		frustum.right	=  ratio * halfLongSide;
	}
	else {
		// Since FOV is specified as the 1/2 width, the ratio
		// is the height/width (different than gluPerspective)
		float ratio = (float)clipInUI3D.Height() / (float)clipInUI3D.Width();

		frustum.top		= ratio * halfLongSide;
		frustum.bottom	= -frustum.top;

		frustum.left	= -halfLongSide;
		frustum.right	=  halfLongSide;
	}
	
	Matrix4 rot;
	rot.SetZRotation( (float)(-90 * Rotation()) );
	
	// In normalized coordinates.
	projection3D.SetFrustum( frustum.left, frustum.right, frustum.bottom, frustum.top, frustum.zNear, frustum.zFar );
	projection3D = projection3D * rot;
	GPUShader::SetPerspectiveTransform( frustum.left, frustum.right,
										frustum.bottom, frustum.top,	
										frustum.zNear, frustum.zFar,
										(90*Rotation()) );
}