1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include <string>
#include "SDL/SDL.h"
using namespace std;
class functions{
public:
SDL_Surface* load_image(string filename)
{
SDL_Surface* unoptimisedLoadedImage = NULL;
SDL_Surface* optimisedLoadedImage = NULL;
unoptimisedLoadedImage = SDL_LoadBMP( filename.c_str() );
if(unoptimisedLoadedImage != NULL)
{
optimisedLoadedImage = SDL_DisplayFormat(unoptimisedLoadedImage);
SDL_FreeSurface(unoptimisedLoadedImage);
}
return optimisedLoadedImage;
}
void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination)
{
//Temporary rectangle to hold offsets.
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface(source, NULL, destination, &offset);
}
};
int main(int argc, char* args[])
{
functions Fo;
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
{
return 1;
}
SDL_Surface* Message = Fo.load_image("EthanChromeCrystal.bmp");
SDL_Surface* Background = Fo.load_image("SDLTestBg1.bmp");
SDL_Surface* Screen = SDL_SetVideoMode(960,600,32,SDL_SWSURFACE);
if(Screen == NULL)
{
return 1;
}
SDL_WM_SetCaption("Example Program!", NULL);
Fo.apply_surface(0,0,Background,Screen);
Fo.apply_surface(480,0,Background,Screen);
Fo.apply_surface(0,300,Background,Screen);
Fo.apply_surface(480,300,Background,Screen);
Fo.apply_surface(240,150,Message,Screen);
if(SDL_Flip(Screen)==-1)
{
return 1;
}
SDL_Delay(5000);
SDL_FreeSurface(Message);
SDL_FreeSurface(Background);
SDL_Quit();
return 0;
}
|