Пример #1
0
int main( int argc, char** argv )
{
  // Create the hidden program options (required args)
  boost::program_options::options_description hidden( "Hidden options" );
  hidden.add_options()
    ("image",
     boost::program_options::value<std::string>(),
     "the image (with path) that will be used\n");
    
  // Create the positional (required) args
  boost::program_options::positional_options_description pd;
  pd.add("image", 1 );
  
  // Create the optional arguments
  boost::program_options::options_description generic( "Allowed options" );
  generic.add_options()
    ("help,h", "produce help message")
    ("color_key_red,r",
     boost::program_options::value<unsigned>(),
     "the color key red value (0-255)\n")
    ("color_key_green,g",
     boost::program_options::value<unsigned>(),
     "the color key green value (0-255)\n")
    ("color_key_blue,b",
     boost::program_options::value<unsigned>(),
     "the color key blue value (0-255)\n");

  // Create the command-line argument parser
  boost::program_options::options_description
    cmdline_options( "Allowed options" );
  cmdline_options.add(generic).add(hidden);

  boost::program_options::variables_map vm;
  boost::program_options::store( boost::program_options::command_line_parser(argc, argv).options(cmdline_options).positional(pd).run(), vm );
  boost::program_options::notify( vm );

  // Check if the help message was requested
  if( vm.count( "help" ) )
  {
    std::cerr << cmdline_options << std::endl;
    
    return 1;
  }

  // Store the image name
  std::string image_name;

  if( vm.count( "image" ) )
    image_name = vm["image"].as<std::string>();
  else
  {
    std::cerr << "The image (with path) must be specified."
	      << std::endl;

    return 1;
  }

  // Store the color key rgb values
  unsigned char color_key_r = 255, color_key_g = 255, color_key_b = 255;

  if( vm.count( "color_key_red" ) )
    color_key_r = vm["color_key_red"].as<unsigned>();

  if( vm.count( "color_key_green" ) )
    color_key_g = vm["color_key_green"].as<unsigned>();

  if( vm.count( "color_key_blue" ) )
    color_key_b = vm["color_key_blue"].as<unsigned>();
  
  // Initialize the window
  if( !initialize() )
    return 1;
  else
  {
    // Load the bitmap
    if( !loadMedia( image_name, color_key_r, color_key_g, color_key_b ) )
      return 1;
    else
    {
      bool quit = false;

      // The event
      SDL_Event event;

      // The current animation frame
      int frame = 0;
      
      // Main application loop
      while( !quit )
      {
	while( SDL_PollEvent( &event ) != 0 )
	{
	  if( event.type == SDL_QUIT )
	    quit = true;
	}

	// Clear the screen
	SDL_SetRenderDrawColor( g_renderer, 0xFF, 0xFF, 0xFF, 0xFF );
	
	SDL_RenderClear( g_renderer );

	// Render the current frame
	SDL_Rect* current_clip = &g_sprite_clips[frame/4];
	
	g_sprite_sheet_texture.render( (screen_width_height[0] -
					current_clip->w)/2,
				       (screen_width_height[1] - 
					current_clip->h)/2,
				       current_clip );
	
	// Update the screen
	SDL_RenderPresent( g_renderer );

	// Increment the frame
	++frame;

	// Reset animation
	if( frame/4 >= g_frames )
	  frame = 0;
      }
    }
  }
  
  // Close program
  close();

  return 0;
}
Пример #2
0
int main( int argc, char** argv )
{
  // Create the hidden program options (required args)
  boost::program_options::options_description hidden( "Hidden options" );
  hidden.add_options()
    ("image",
     boost::program_options::value<std::string>(),
     "the image (with path) that will be used\n");
    
  // Create the positional (required) args
  boost::program_options::positional_options_description pd;
  pd.add("image", 1 );
  
  // Create the optional arguments
  boost::program_options::options_description generic( "Allowed options" );
  generic.add_options()
    ("help,h", "produce help message")
    ("color_key_red,r",
     boost::program_options::value<unsigned>(),
     "the color key red value (0-255)\n")
    ("color_key_green,g",
     boost::program_options::value<unsigned>(),
     "the color key green value (0-255)\n")
    ("color_key_blue,b",
     boost::program_options::value<unsigned>(),
     "the color key blue value (0-255)\n");

  // Create the command-line argument parser
  boost::program_options::options_description
    cmdline_options( "Allowed options" );
  cmdline_options.add(generic).add(hidden);

  boost::program_options::variables_map vm;
  boost::program_options::store( boost::program_options::command_line_parser(argc, argv).options(cmdline_options).positional(pd).run(), vm );
  boost::program_options::notify( vm );

  // Check if the help message was requested
  if( vm.count( "help" ) )
  {
    std::cerr << cmdline_options << std::endl;
    
    return 1;
  }

  // Store the image name
  std::string image_name;

  if( vm.count( "image" ) )
    image_name = vm["image"].as<std::string>();
  else
  {
    std::cerr << "The image (with path) must be specified."
	      << std::endl;

    return 1;
  }

  // Store the color key rgb values
  unsigned char color_key_r = 255, color_key_g = 255, color_key_b = 255;

  if( vm.count( "color_key_red" ) )
    color_key_r = vm["color_key_red"].as<unsigned>();

  if( vm.count( "color_key_green" ) )
    color_key_g = vm["color_key_green"].as<unsigned>();

  if( vm.count( "color_key_blue" ) )
    color_key_b = vm["color_key_blue"].as<unsigned>();
  
  // Initialize the window
  if( !initialize() )
    return 1;
  else
  {
    // Load the bitmap
    if( !loadMedia( image_name, color_key_r, color_key_g, color_key_b ) )
      return 1;
    else
    {
      bool quit = false;

      // The event
      SDL_Event event;

      // The modulation components
      unsigned char r = 255, g = 255, b = 255;
      
      // Main application loop
      while( !quit )
      {
	while( SDL_PollEvent( &event ) != 0 )
	{
	  if( event.type == SDL_QUIT )
	    quit = true;

	  // On keypress, change rgb values
	  else if( event.type == SDL_KEYDOWN )
	  {
	    switch( event.key.keysym.sym )
	    {
	      // Increase red
	      case SDLK_q:
		r += 32;
		break;

	      // Increase green
	      case SDLK_w:
		g += 32;
		break;

	      // Increase blue
	      case SDLK_e:
		b += 32;
		break;
		
	      // Decrease red
	      case SDLK_a:
		r -= 32;
		break;

	      // Decrease green
	      case SDLK_s:
		g -= 32;
		break;

	      // Decrease blue
	      case SDLK_d:
		b -= 32;
		break;
	    }
	  }
	}

	// Clear the screen
	SDL_SetRenderDrawColor( g_renderer, 0xFF, 0xFF, 0xFF, 0xFF );
	
	SDL_RenderClear( g_renderer );

	// Modulate the render texture
	g_modulated_texture.setColor( r, g, b );
	g_modulated_texture.render( 0, 0 );
	
	// Update the screen
	SDL_RenderPresent( g_renderer );
      }
    }
  }
  
  // Close program
  close();

  return 0;
}
Пример #3
0
int main( int argc, char** argv )
{
  // Create the hidden program options (required args)
  boost::program_options::options_description hidden( "Hidden options" );
  hidden.add_options()
    ("foreground",
     boost::program_options::value<std::string>(),
     "the foreground image (with path) that will be used\n")
    ("background",
     boost::program_options::value<std::string>(),
     "the background image (with path) that will be used\n");

  // Create the positional (required) args
  boost::program_options::positional_options_description pd;
  pd.add("foreground", 1 );
  pd.add("background", 2 );

  // Create the optional arguments
  boost::program_options::options_description generic( "Allowed options" );
  generic.add_options()
    ("help,h", "produce help message");

  // Create the command-line argument parser
  boost::program_options::options_description
    cmdline_options( "Allowed options" );
  cmdline_options.add(generic).add(hidden);

  boost::program_options::variables_map vm;
  boost::program_options::store( boost::program_options::command_line_parser(argc, argv).options(cmdline_options).positional(pd).run(), vm );
  boost::program_options::notify( vm );

  // Check if the help message was requested
  if( vm.count( "help" ) )
  {
    std::cerr << cmdline_options << std::endl;
    
    return 1;
  }

  // Store the image name
  std::string foreground_image_name, background_image_name;

  if( vm.count( "foreground" ) )
    foreground_image_name = vm["foreground"].as<std::string>();
  else
  {
    std::cerr << "The foreground image (with path) must be specified."
	      << std::endl;

    return 1;
  }

  if( vm.count( "background" ) )
    background_image_name = vm["background"].as<std::string>();
  else
  {
    std::cerr << "The background image (with path) must be specified."
	      << std::endl;

    return 1;
  }
  
  std::cout << foreground_image_name << " " << background_image_name << std::endl;
  // Initialize the window
  if( !initialize() )
    return 1;
  else
  {
    // Load the bitmap
    if( !loadMedia( foreground_image_name, background_image_name ) )
      return 1;
    else
    {
      bool quit = false;

      // Event
      SDL_Event event;

      // Main application loop
      while( !quit )
      {
	while( SDL_PollEvent( &event ) != 0 )
	{
	  if( event.type == SDL_QUIT )
	    quit = true;
	}

	// Clear the screen
	SDL_SetRenderDrawColor( g_renderer, 0xFF, 0xFF, 0xFF, 0xFF );
	SDL_RenderClear( g_renderer );

	// Render background texture to screen
	g_background.render( 0, 0 );

	// Render foreground texture to screen
	g_foreground.render( 240, 190 );

	// Update the screen
	SDL_RenderPresent( g_renderer );
      }
    }
  }
  
  // Close program
  close();

  return 0;
}