Exemplo n.º 1
0
void TestBlitter::SetUp(	KrRGBA newColorBase,
							KrRGBA surfaceColorBase,
							KrColorTransform cformBase  )
{
	KrRGBA newColor;
	KrRGBA surfaceColor;
	KrColorTransform cform;

	// NoAlpha in source
	// -- Simple transform
	cform.Set( 255, 0, 255, 0, 255, 0, 255 );
	surfaceColor = surfaceColorBase;
	newColor     = newColorBase;
	newColor.c.alpha = 255;
	Run( surfaceColor, newColor, cform, false );

	// -- Color transform
	cform = cformBase;
	cform.SetAlpha( 255 );
	surfaceColor = surfaceColorBase;
	newColor     = newColorBase;
	newColor.c.alpha = 255;
	Run( surfaceColor, newColor, cform, false );

	// -- Alpha transform
	cform = cformBase;
	cform.SetRed( 255, 0 );
	cform.SetGreen( 255, 0 );
	cform.SetBlue( 255, 0 );
	surfaceColor = surfaceColorBase;
	newColor     = newColorBase;
	newColor.c.alpha = 255;
	Run( surfaceColor, newColor, cform, false );

	// -- Full transform
	cform = cformBase;
	surfaceColor = surfaceColorBase;
	newColor     = newColorBase;
	newColor.c.alpha = 255;
	Run( surfaceColor, newColor, cform, false );


	// Alpha in source
	// -- Simple transform
	cform.Set( 255, 0, 255, 0, 255, 0, 255 );
	surfaceColor = surfaceColorBase;
	newColor     = newColorBase;
	Run( surfaceColor, newColor, cform, true );

	// -- Color transform
	cform = cformBase;
	cform.SetAlpha( 255 );
	surfaceColor = surfaceColorBase;
	newColor     = newColorBase;
	Run( surfaceColor, newColor, cform, true );

	// -- Alpha transform
	cform = cformBase;
	cform.SetRed( 255, 0 );
	cform.SetGreen( 255, 0 );
	cform.SetBlue( 255, 0 );
	surfaceColor = surfaceColorBase;
	newColor     = newColorBase;
	Run( surfaceColor, newColor, cform, true );

	// -- Full transform
	cform = cformBase;
	surfaceColor = surfaceColorBase;
	newColor     = newColorBase;
	Run( surfaceColor, newColor, cform, true );
}
Exemplo n.º 2
0
TileTest::TileTest( SDL_Surface* _screen )
{
	drawn = false;
	screen = _screen;
	engine = new KrEngine( screen );
	//GLOUTPUT( "TileTest::TileTest\n" );
	engine->Validate();	// check validity

	int i, j;

	// Classes to hold other objects:
	engine->Vault()->LoadDatFile( "standardtest.dat" );

	KrTileResource* noAlphaRes = engine->Vault()->GetTileResource( "NOALPHA" );
	KrTileResource* alphaRes = engine->Vault()->GetTileResource( "ALPHA" );
	GLASSERT( noAlphaRes && alphaRes );

	// Transforms:
	KrColorTransform alphaCForm;
	alphaCForm.SetAlpha( 255 * 70 / 100 );

	KrColorTransform redCForm;
	redCForm.SetRed( 255 * 50 / 100, 127 );

	KrColorTransform blueCForm;
	blueCForm.SetBlue( 255 * 50 / 100, 127 );

	KrColorTransform greenAlphaCForm;
	greenAlphaCForm.SetGreen( 255 * 50 / 100, 127 );
	greenAlphaCForm.SetAlpha( 255 * 70 / 100 );

	KrColorTransform blueAlphaCForm;
	blueAlphaCForm.SetBlue( 255 * 50 / 100, 127 );
	blueAlphaCForm.SetAlpha( 255 * 70 / 100 );

	// Containers:
	KrImNode* c0 = new KrImNode;	// background
	KrImNode* c1 = new KrImNode;	// tiles
 	KrImNode* c2 = new KrImNode;	// canvas

	engine->Tree()->AddNode( 0, c0 );
	engine->Tree()->AddNode( c0, c1 );
	engine->Tree()->AddNode( c0, c2 );

	c1->SetPos(   0,   0 );
	c2->SetPos(	420,   0 );
	c1->SetZDepth( 1 );
	c2->SetZDepth( 1 );

	// ---------- Background ----------- //
	KrSpriteResource* backSpriteRes = engine->Vault()->GetSpriteResource( "BACKGROUND" );
	GLASSERT( backSpriteRes );
	KrAction* action = backSpriteRes->GetActionByIndex( 0 );
	GLASSERT( action );
	const KrRle& rle = action->Frame( 0 );

	for ( i=0; i <= (screen->w) / rle.Width(); i++ )
	{
		for ( j=0; j <= (screen->h) / rle.Height(); j++ )
		{
			KrSprite* sprite = new KrSprite( backSpriteRes );
			sprite->SetPos( i*rle.Width(), j*rle.Height() );
			GLASSERT( sprite );
			engine->Tree()->AddNode( c0, sprite );
		}
	}

	// ---------- The "no alpha" tile.
	// no transform:
	for ( i=0; i<8; i++ )
	{
		noAlpha[i][0] = new KrTile( noAlphaRes );
		noAlpha[i][0]->SetPos( i*noAlpha[i][0]->Size(), 0 );
		noAlpha[i][0]->SetRotation( i );
		GLASSERT( noAlpha );
		engine->Tree()->AddNode( c1, noAlpha[i][0] );
	}

	// alpha:
	for ( i=0; i<8; i++ )
	{
		noAlpha[i][1] = new KrTile( noAlphaRes );
		noAlpha[i][1]->SetColor( alphaCForm );
		noAlpha[i][1]->SetPos( i*noAlpha[i][1]->Size(), 1*noAlpha[i][1]->Size() );
		noAlpha[i][1]->SetRotation( i );
		GLASSERT( noAlpha[i][1] );
		engine->Tree()->AddNode( c1, noAlpha[i][1] );
	}

	// red:
	for ( i=0; i<8; i++ )
	{
		noAlpha[i][2] = new KrTile( noAlphaRes );
		noAlpha[i][2]->SetColor( redCForm );
		noAlpha[i][2]->SetPos( i*noAlpha[i][2]->Size(), 2*noAlpha[i][2]->Size() );
		noAlpha[i][2]->SetRotation( i );
		GLASSERT( noAlpha[i][2] );
		engine->Tree()->AddNode( c1, noAlpha[i][2] );
	}

	// combination:
	for ( i=0; i<8; i++ )
	{
		noAlpha[i][3] = new KrTile( noAlphaRes );
		noAlpha[i][3]->SetColor( blueAlphaCForm );
		noAlpha[i][3]->SetPos( i*noAlpha[i][3]->Size(), 3*noAlpha[i][3]->Size() );
		noAlpha[i][3]->SetRotation( i );
		GLASSERT( noAlpha );
		engine->Tree()->AddNode( c1, noAlpha[i][3] );
	}

	// ---------- The "alpha" tile.
	// no transform:
	for ( i=0; i<8; i++ )
	{
// 		i=6;
		alpha[i][0] = new KrTile( alphaRes );
		alpha[i][0]->SetPos( i*alpha[i][0]->Size(), 4*alpha[i][0]->Size() );
		alpha[i][0]->SetRotation( i );
		GLASSERT( alpha[i][0] );
		engine->Tree()->AddNode( c1, alpha[i][0] );
	}

	// alpha:
	for ( i=0; i<8; i++ )
	{
		alpha[i][1] = new KrTile( alphaRes );
		alpha[i][1]->SetColor( alphaCForm );
		alpha[i][1]->SetPos( i*alpha[i][1]->Size(), 5*alpha[i][1]->Size() );
		alpha[i][1]->SetRotation( i );
		GLASSERT( alpha[i][1] );
		engine->Tree()->AddNode( c1, alpha[i][1] );
	}

	// red:
	for ( i=0; i<8; i++ )
	{
		alpha[i][2] = new KrTile( alphaRes );
		alpha[i][2]->SetColor( redCForm );
		alpha[i][2]->SetPos( i*alpha[i][2]->Size(), 6*alpha[i][2]->Size() );
		alpha[i][2]->SetRotation( i );
		GLASSERT( alpha[i][2] );
		engine->Tree()->AddNode( c1, alpha[i][2] );
	}

	// combination:
	for ( i=0; i<8; i++ )
	{
		alpha[i][3] = new KrTile( alphaRes );
		alpha[i][3]->SetColor( blueAlphaCForm );
		alpha[i][3]->SetPos( i*alpha[i][3]->Size(), 7*alpha[i][3]->Size() );
		alpha[i][3]->SetRotation( i );
		GLASSERT( alpha[i][3] );
		engine->Tree()->AddNode( c1, alpha[i][3] );
	}

	// ----------- A canvas ----------------- //
	KrCanvasResource* canvasResource = new KrCanvasResource( "mycanvas",
															 50, 50,
															 true );
	engine->Vault()->AddResource( canvasResource );
	KrRGBA* pixels = canvasResource->Pixels();
	KrRGBA color;
	for( i=0; i<canvasResource->Width(); i++ )
	{
		for( j=0; j<canvasResource->Height(); j++ )
		{
			color.c.red = i*4 + 50;
			color.c.green = j*4 + 50;
			color.c.blue = 0;
			color.c.alpha = 255 - i;
			pixels[ j*canvasResource->Width() + i ] = color;
		}
		// Put in a diagonal line:
		color.Set( 0, 0, 255 );
		pixels[ i*canvasResource->Width() + i ] = color;
	}

	const int NUMCANVASDIV2 = NUMCANVAS / 2;
	for ( i=0; i<NUMCANVASDIV2; i++ )
	{
		GlFixed sx;
		GlFixed sy;

		// The left canvas:
		canvas[i*2] = new KrCanvas( canvasResource );

		engine->Tree()->AddNode( c2, canvas[i*2] );
		canvas[i*2]->SetPos( 0, i * canvas[i*2]->Height() * 3 / 2 );
		sx.v = GlFixed_1 * (i+1) / 3;
		sy.v = GlFixed_1 * (i+1) / 3;

		canvas[i*2]->SetScale( sx, sy );

		// The right canvas:
		canvas[i*2+1] = new KrCanvas( canvasResource );
		engine->Tree()->AddNode( c2, canvas[i*2+1] );

		canvas[i*2+1]->SetPos( 100, i * canvas[i*2+1]->Height() * 3 / 2 );
		sx.v = GlFixed_1 * (NUMCANVASDIV2 + 1 - i) / 3;
		sy.v = GlFixed_1 * (i+1) / 3;

		canvas[i*2+1]->SetScale( sx, sy );
	}
}