コード例 #1
0
bool loadMedia()
{
	//Loading success flag
	bool success = true;

	//Load dot texture
	if( !gDotTexture.loadFromFile( "assets/38_particle_engines/dot.bmp" ) )
	{
		printf( "Failed to load dot texture!\n" );
		success = false;
	}

	//Load red texture
	if( !gRedTexture.loadFromFile( "assets/38_particle_engines/red.bmp" ) )
	{
		printf( "Failed to load red texture!\n" );
		success = false;
	}

	//Load green texture
	if( !gGreenTexture.loadFromFile( "assets/38_particle_engines/green.bmp" ) )
	{
		printf( "Failed to load green texture!\n" );
		success = false;
	}

	//Load blue texture
	if( !gBlueTexture.loadFromFile( "assets/38_particle_engines/blue.bmp" ) )
	{
		printf( "Failed to load blue texture!\n" );
		success = false;
	}

	//Load shimmer texture
	if( !gShimmerTexture.loadFromFile( "assets/38_particle_engines/shimmer.bmp" ) )
	{
		printf( "Failed to load shimmer texture!\n" );
		success = false;
	}
	
	//Set texture transparency
	gRedTexture.setAlpha( 192 );
	gGreenTexture.setAlpha( 192 );
	gBlueTexture.setAlpha( 192 );
	gShimmerTexture.setAlpha( 192 );

	return success;
}
コード例 #2
0
void Scoreboard::render( SDL_Renderer* gRenderer, TTF_Font* gFont, LTexture gTextTexture ) {
	string s = std::to_string( static_cast<long long>( score ) );
	s = string( 10 - s.size(), ' ' ) + s;
	string text = "Score: " + s;
	gTextTexture.loadFromRenderedText( text, textColor );
	gTextTexture.setBlendMode( SDL_BLENDMODE_BLEND );
	gTextTexture.setAlpha( 150 );
	gTextTexture.render( xPos, yPos, gRenderer );
}
コード例 #3
0
ファイル: alpha_blending.cpp プロジェクト: LXiong/blog_tmp
int
main(int argc, char *argv[])
{
	int quit = 0;
	/* event handler */
	SDL_Event event;
	/* modulation components */
	Uint8 alpha = 255;


	/* starts up SDL and create window */
	if (init_sdl() == -1) {
		fprintf(stderr, "Failed to initialize SDL!\n");
		return -1;
	}

	/* load media */
	if (load_media() == -1) {
		fprintf(stderr, "Failed to load media!\n");
		return -2;
	}

	/* main loop */
	while (quit == 0) {
		/* handle events on queue */
		while (SDL_PollEvent(&event) != 0) {
			/* users request quit */
			if (event.type == SDL_QUIT)
				quit = 1;

			/* on key press change alpha values */
			else if (event.type == SDL_KEYDOWN) {
				/* increase alpha on w */
				if (event.key.keysym.sym == SDLK_w) {
					if (alpha + 32 > 255)
						alpha = 255;
					else
						alpha += 32;

				/* decrease alpha on s */
				} else if (event.key.keysym.sym == SDLK_s) {
					if (alpha - 32 < 0)
						alpha = 0;
					else
						alpha -= 32;
				}
			}
		}

		/* clear screen */
		SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
		SDL_RenderClear(gRenderer);

		/* render background */
		gBackgroundTexture.render(0, 0);

		/* render front blended */
		gModulatedTexture.setAlpha(alpha);
		gModulatedTexture.render(0, 0);


		/* update screen */
		SDL_RenderPresent(gRenderer);
	}

	/* free resources and close */
	close_sdl();

	return 0;
}
コード例 #4
0
int main( int argc, char* args[] )
{
	//Start up SDL and create window
	if( !init() )
	{
		printf( "Failed to initialize!\n" );
	}
	else
	{
		//Load media
		if( !loadMedia() )
		{
			printf( "Failed to load media!\n" );
		}
		else
		{
			//Main loop flag
			bool quit = false;

			//Event handler
			SDL_Event e;

			//Modulation component
			Uint8 a = 255;

			//While application is running
			while( !quit )
			{
				//Handle events on queue
				while( SDL_PollEvent( &e ) != 0 )
				{
					//User requests quit
					if( e.type == SDL_QUIT )
					{
						quit = true;
					}
					//Handle key presses
					else if( e.type == SDL_KEYDOWN )
					{
						//Increase alpha on w
						if( e.key.keysym.sym == SDLK_w )
						{
							//Cap if over 255
							if( a + 32 > 255 )
							{
								a = 255;
							}
							//Increment otherwise
							else
							{
								a += 32;
							}
						}
						//Decrease alpha on s
						else if( e.key.keysym.sym == SDLK_s )
						{
							//Cap if below 0
							if( a - 32 < 0 )
							{
								a = 0;
							}
							//Decrement otherwise
							else
							{
								a -= 32;
							}
						}
					}
				}

				//Clear screen
				SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
				SDL_RenderClear( gRenderer );

				//Render background
				gBackgroundTexture.render( 0, 0 );

				//Render front blended
				gModulatedTexture.setAlpha( a );
				gModulatedTexture.render( 0, 0 );

				//Update screen
				SDL_RenderPresent( gRenderer );
			}
		}
	}

	//Free resources and close SDL
	close();

	return 0;
}