Skip to content

Instantly share code, notes, and snippets.

@flightcrank
Created September 28, 2012 13:13
Show Gist options
  • Save flightcrank/3799757 to your computer and use it in GitHub Desktop.
Save flightcrank/3799757 to your computer and use it in GitHub Desktop.
sdl load image function
//Global variables
SDL_Surface *title_screen;
int load_image(char filename[], SDL_Surface *surface) {
SDL_Surface *temp;
//load image
temp = SDL_LoadBMP(filename);
if (temp == NULL) {
printf("Unable to load %s.\n", filename);
return 1;
}
/* Set the image colorkey. */
Uint32 colorkey = SDL_MapRGB(temp->format, 255, 0, 255);
SDL_SetColorKey(temp, SDL_SRCCOLORKEY, colorkey);
//convert the image surface to the same type as the screen
surface = SDL_DisplayFormat(temp);
if (surface == NULL) {
printf("Unable to convert bitmap.\n");
return 1;
}
SDL_FreeSurface(temp);
return 0;
}
main() {
//set up SDL
// code
//....
load_image("image.bmp", title_screen); //(title_screen is global)
//more code
//game loop ect
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment