#ifdef HAVE_CONFIG_H #include #endif #include #include #include "SDL.h" #include "SDL/SDL_image.h" using namespace std; const int SCREENWIDTH = 500; const int SCREENHEIGHT = 500; const int SCREENBPP = 32; SDL_Surface *Box = NULL; SDL_Surface *Bg = NULL; SDL_Surface *Screen = NULL; SDL_Event event; SDL_Surface *load_image (std::string filename) { SDL_Surface *first_act_image = NULL; SDL_Surface *optimized_image = NULL; first_act_image = IMG_Load( filename.c_str() ); if (first_act_image != NULL) { optimized_image = SDL_DisplayFormat (first_act_image); SDL_FreeSurface (first_act_image); } return optimized_image; } void apply_surface (int x, int y, SDL_Surface* source, SDL_Surface* destination) { SDL_Rect offset; offset.x = x; offset.y = y; SDL_BlitSurface (source, NULL, destination, &offset); } int main (int argc, char* argv []) { bool quit = false; if (SDL_Init(SDL_INIT_EVERYTHING) == -1) { return 1; } Screen = SDL_SetVideoMode (SCREENWIDTH, SCREENHEIGHT, SCREENBPP, SDL_SWSURFACE); if(Screen == NULL) { return 1; } SDL_WM_SetCaption ("HelloSDL", NULL); Box = load_image ("image.png"); Bg = load_image ("background.png"); apply_surface (0, 0, Bg, Screen); apply_surface (25, 30, Box, Screen); if (SDL_Flip (Screen) == -1) { return 1; } while (quit == false) { while (SDL_PollEvent (&event)) { if (event.type == SDL_QUIT) { quit = true; } } } SDL_FreeSurface (Box); SDL_FreeSurface (Bg); SDL_Quit(); return 0; }