daily pastebin goal
67%
SHARE
TWEET

Untitled

a guest Jun 18th, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "SDL/SDL.h"
  2. #include <string>
  3. #include <iostream>
  4.  
  5. //Attributes
  6. const int SCREEN_WIDTH = 640;
  7. const int SCREEN_HEIGHT = 480;
  8. const int SCREEN_BPP = 32;
  9.  
  10. //Surfaces
  11. SDL_Surface* message = NULL;
  12. SDL_Surface* background = NULL;
  13. SDL_Surface* screen = NULL;
  14.  
  15. SDL_Surface* load_image(std::string filename)
  16. // Оптимизированная загрузка изображения.
  17. {
  18.     SDL_Surface* loadedImage = NULL;
  19.     SDL_Surface* optimizedImage = NULL;
  20.  
  21.     loadedImage = SDL_LoadBMP(filename.c_str());
  22.  
  23.     if (loadedImage != NULL)
  24.     {
  25.         optimizedImage = SDL_DisplayFormat(loadedImage);
  26.         SDL_FreeSurface(loadedImage);
  27.     }
  28.     else
  29.     {
  30.         std::cout << "[W]: Ошибка загрузки " << filename.c_str() <<std::endl;
  31.     }
  32.  
  33.     return optimizedImage;
  34. }
  35.  
  36. void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination)
  37. {
  38.     SDL_Rect offset;
  39.  
  40.     offset.x = x;
  41.     offset.y = y;
  42.  
  43.     SDL_BlitSurface(source, NULL, destination, &offset);
  44. }
  45.  
  46. int main(int argc, char** args)
  47. {
  48.     if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
  49.     {
  50.         std::cout << "[!]: Ошибка инициализации SDL" << std::endl;
  51.         return 1;
  52.     }
  53.  
  54.     screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
  55.     if (screen == NULL)
  56.     {
  57.         std::cout << "[!]: Ошибка инициализации экрана" << std::endl;
  58.         return 1;
  59.     }
  60.  
  61.     SDL_WM_SetCaption("Hello World!", NULL);
  62.  
  63.     message = load_image("message.bmp");
  64.     background = load_image("background.bmp");
  65.  
  66.     apply_surface(0, 0, background, screen);
  67.     apply_surface(320, 0, background, screen);
  68.     apply_surface(0, 240, background, screen);
  69.     apply_surface(320, 240, background, screen);
  70.  
  71.     apply_surface(180, 140, message, screen);
  72.  
  73.     if (SDL_Flip(screen) == -1)
  74.     {
  75.         std::cout << "[!]: Ошибка функции Flip" << std::endl;
  76.         return 1;
  77.     }
  78.  
  79.     SDL_Delay(3000);
  80.  
  81.     SDL_FreeSurface(message);
  82.     SDL_FreeSurface(background);
  83.  
  84.     SDL_Quit();
  85.  
  86.     return 0;
  87. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top