Advertisement
Benjamin_Loison

main.cpp (TerraCraft)

May 3rd, 2017
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include <SDL.h>
  2. #include <SDL_image.h>
  3. #include <SDL_ttf.h>
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. void draw();
  8.  
  9. int main(int argc, char** argv)
  10. {
  11.     const string name = "TerraCraft";
  12.     const char pathSeparator =
  13.     #ifdef _WIN32
  14.                             '\\';
  15.     #else
  16.                             '/';
  17.     #endif
  18.     SDL_Window *screen;
  19.     SDL_Surface *text;
  20.     SDL_Rect position;
  21.     SDL_Event event;
  22.     TTF_Font *font;
  23.     SDL_Color blackColor = {0, 0, 0};
  24.     bool opened = true;
  25.  
  26.     SDL_Init(SDL_INIT_VIDEO);
  27.     TTF_Init();
  28.  
  29.     screen = SDL_CreateWindow(name.c_str(), 100, 100, 1920, 400, SDL_WINDOW_MAXIMIZED | SDL_WINDOW_RESIZABLE);
  30.  
  31.     while(opened)
  32.     {
  33.         SDL_WaitEvent(&event);
  34.         switch(event.type)
  35.         {
  36.             case SDL_QUIT:
  37.                 opened = 0;
  38.                 break;
  39.             case SDL_WINDOWEVENT:
  40.                 if(event.window.event == SDL_WINDOWEVENT_RESIZED)
  41.                 {
  42.  
  43.     SDL_Surface *pSurf = SDL_GetWindowSurface(screen);
  44.     font = TTF_OpenFont("arial.ttf", 55);
  45.     text = TTF_RenderText_Blended(font, "etc", blackColor);
  46.                     SDL_FillRect(pSurf, NULL, SDL_MapRGB(pSurf->format, 255, 255, 255));
  47.                     position.x = 0;
  48.                     position.y = 0;
  49.                     SDL_BlitSurface(IMG_Load("parc.png"), NULL, pSurf, &position);
  50.                     position.x = 60;
  51.                     position.y = 370;
  52.                     SDL_BlitSurface(text, NULL, pSurf, &position);
  53.                     SDL_UpdateWindowSurface(screen);
  54.                     break;
  55.                 }
  56.             }
  57.         }
  58.  
  59.     TTF_CloseFont(font);
  60.     TTF_Quit();
  61.  
  62.     SDL_FreeSurface(text);
  63.     SDL_Quit();
  64.  
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement