#include <SDL/SDL.h> /* Function to load and return an optimised image * using the SDL graphics libraries * author: Danny Battison * contact: [email protected] */ SDL_Surface *Load_Optimal (char *filename) { SDL_Surface *loaded = NULL; /* The surface to load the basic image */ SDL_Surface *optimal = NULL; /* The optimised surface */ loaded = SDL_LoadBMP (filename); /* Load the basic image */ if (loaded != NULL) /* This is why NULL is important, now we can check if it was loaded successfully */ { optimal = SDL_DisplayFormat (loaded); /* Load an optimised version of the basic surface */ SDL_FreeSurface (loaded); /* Delete the basic one, it's no longer needed */ } return optimal; /* Return the optimised image */ } /***********ALTERNATIVE, IF YOU USE SDL_IMAGE.H *************/ #include <SDL/SDL.h> #include <SDL/SDL_image.h> SDL_Surface *Load_Optimal (char *filename) { SDL_Surface *loaded = NULL; /* The surface to load the basic image */ SDL_Surface *optimal = NULL; /* The optimised surface */ loaded = IMG_Load (filename); /* Load the basic image */ if (loaded != NULL) /* This is why NULL is important, now we can check if it was loaded successfully */ { optimal = SDL_DisplayFormat (loaded); /* Load an optimised version of the basic surface */ SDL_FreeSurface (loaded); /* Delete the basic one, it's no longer needed */ } return optimal; /* Return the optimised image */ }
SDL: Load an optimised image to a surface
Page 1 of 10 Replies - 87 Views - Last Post: 11 July 2008 - 08:14 AM
#1
SDL: Load an optimised image to a surface
Posted 11 July 2008 - 08:14 AM
Description: Pass the file path to the function :) | If you have SDL_Image stuff to load other file types, replace SDL_LoadBMP with IMG_Load and #include <SDL/SDL_image.h> (example shown in the code)A function to load and optimise an image.
Page 1 of 1

New Topic/Question
Reply






MultiQuote

|