Advertisement
Guest User

mathnumgraph

a guest
Mar 26th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.19 KB | None | 0 0
  1. // SDL2 Hello, World!
  2. // This should display a white screen for 2 seconds
  3. // compile with: clang++ main.cpp -o hello_sdl2 -lSDL2
  4. // run with: ./hello_sdl2
  5. #include <SDL2/SDL.h>
  6. #include <stdio.h>
  7. #include <SDL2/SDL2_gfxPrimitives.h>
  8.  
  9. #define SCREEN_WIDTH 640
  10. #define SCREEN_HEIGHT 480
  11.  
  12. int main(int argc, char* args[]) {
  13.     SDL_Window* window = NULL;
  14.     SDL_Surface* screenSurface = NULL;
  15.  
  16.     if (SDL_Init(SDL_INIT_VIDEO) < 0) {
  17.         fprintf(stderr, "could not initialize sdl2: %s\n", SDL_GetError());
  18.         return 1;
  19.     }
  20.  
  21.     window = SDL_CreateWindow(
  22.         "hello_sdl2",
  23.         SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
  24.         SCREEN_WIDTH, SCREEN_HEIGHT,
  25.         SDL_WINDOW_SHOWN
  26.     );
  27.  
  28.     if (window == NULL) {
  29.         fprintf(stderr, "could not create window: %s\n", SDL_GetError());
  30.         return 1;
  31.     }
  32.  
  33.     SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
  34.     screenSurface = SDL_GetWindowSurface(window);
  35.     SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF));
  36.  
  37.     filledCircleColor(renderer, 320, 240, 10, 0x0000FFFF);
  38.  
  39.     SDL_RenderPresent(renderer);
  40.     SDL_UpdateWindowSurface(window);
  41.     SDL_Delay(2000);
  42.     SDL_DestroyWindow(window);
  43.     SDL_Quit();
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement