What's Here?
- Members: 137,227
- Replies: 481,496
- Topics: 75,061
- Snippets: 2,567
- Tutorials: 675
- Total Online: 1,996
- Members: 100
- Guests: 1,896
|
A function to load and optimise an image.
|
Submitted By: gabehabe
|
|
|
Rating:
|
|
Views: 533 |
Language: C++
|
|
Last Modified: July 11, 2008 |
|
Instructions: 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 (example shown in the code) |
Snippet
#include <SDL/SDL.h>
/* Function to load and return an optimised image
* using the SDL graphics libraries
* author: Danny Battison
* contact: gabehabe@hotmail.com
*/
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 */
}
Copy & Paste
|
|
|
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|