/****************************
Be sure to include the proper header files in your main source file!
*****************************/
SDL_Surface *load_image( std::string filename )
{
//The image that is loaded
SDL_Surface* loadedImage = NULL;
//The optimized image that will be used
SDL_Surface* optimizedImage = NULL;
//Load the image using SDL_image
loadedImage = IMG_Load( filename.c_str() );
//If the image loaded
if( loadedImage != NULL )
{
//Create an optimized image
optimizedImage = SDL_DisplayFormatAlpha( loadedImage );
//Free the old image
SDL_FreeSurface( loadedImage );
}
//Return the optimized image
return optimizedImage;
}
Don't mind the opening comment I have in here, I created a base sort of template for me with some header files to use and reuse for every new SDL project I have, so I don't have to worry about rewriting the same code again and again. Anyway, it's also blitted to the screen using this function:
/****************************
Be sure to include the proper header files in your main source file!
*****************************/
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination )
{
//Rectangle to hold the offsets
SDL_Rect offset;
//Get offsets
offset.x = x;
offset.y = y;
//Blit the surface
SDL_BlitSurface( source, NULL, destination, &offset );
}
These are the two main parts right now, other than when I initialize SDL I have an 800 x 600 fullscreen window.
Any help is appreciated!