Advertisement
Guest User

Untitled

a guest
May 15th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include <SDL/SDL.h>
  2. #include <stdio.h>
  3.  
  4. int main(int argc, char* args[])
  5. {
  6.     SDL_Window* window = NULL;
  7.  
  8.     SDL_Surface* window_surface = NULL;
  9.  
  10.     SDL_Surface* background_surface = NULL;
  11.  
  12.     SDL_Surface* button_surface = NULL;
  13.  
  14.     SDL_Surface* image_3 = NULL;
  15.  
  16.     if (SDL_Init(SDL_INIT_VIDEO) < 0)
  17.     {
  18.         printf("SDL did not init: %s\n", SDL_GetError());
  19.         return 1;
  20.     }
  21.  
  22.     window = SDL_CreateWindow("SDL example", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_SHOWN);
  23.     if (window == NULL)
  24.     {
  25.         printf("Window could not be opened: %s\n", SDL_GetError());
  26.         return 1;
  27.     }
  28.  
  29.     window_surface = SDL_GetWindowSurface(window);
  30.  
  31.     background_surface = SDL_LoadBMP("./background.bmp");
  32.  
  33.     button_surface = SDL_LoadBMP("./button.bmp");
  34.  
  35.     image_3 = SDL_LoadBMP("./image3.bmp");
  36.  
  37.     SDL_Rect image_3_dest_rect;
  38.     image_3_dest_rect.x = 200;
  39.     image_3_dest_rect.y = 200;
  40.  
  41.     int running = 1;
  42.     while (running)
  43.     {
  44.         SDL_Event sevent;
  45.         while (SDL_PollEvent(&sevent))
  46.         {
  47.             switch (sevent.type)
  48.             {
  49.             case SDL_KEYDOWN:
  50.             {
  51.                 if (sevent.key.keysym.sym == SDLK_ESCAPE)
  52.                     running = 0;
  53.                 break;
  54.             }
  55.             case SDL_QUIT:
  56.             {
  57.                 running = 0;
  58.                 break;
  59.             }
  60.             }
  61.         }
  62.  
  63.         SDL_BlitSurface(background_surface, NULL, window_surface, NULL);
  64.  
  65.         SDL_BlitSurface(button_surface, NULL, window_surface, NULL);
  66.  
  67.         SDL_BlitSurface(image_3, NULL, window_surface, &image_3_dest_rect);
  68.  
  69.         SDL_UpdateWindowSurface(window);
  70.     }
  71.  
  72.     SDL_DestroyWindow(window);
  73.  
  74.     SDL_Quit();
  75.  
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement