Advertisement
agmike

SDL Init

Oct 3rd, 2011
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #ifndef INIT_SDL_H
  2. #define INIT_SDL_H
  3.  
  4. /* Include windows.h properly on Windows */
  5. #if defined(WIN32) || defined(_WINDOWS)
  6. #  define WIN32_LEAN_AND_MEAN
  7. #  define NOMINMAX
  8. #  include <windows.h>
  9. #endif
  10.  
  11. /* SDL */
  12. #include <SDL.h>
  13. #include <SDL_opengl.h>
  14. #ifndef INIT_SDL_MAIN
  15. #  undef main
  16. #endif
  17.  
  18. #endif
  19.  
  20.  
  21.  
  22. #define INIT_SDL_MAIN
  23. #include "init_sdl.h"
  24.  
  25. static const int window_width = 800;
  26. static const int window_height = 600;
  27.  
  28. int main(int argc, char** argv)
  29. {
  30.     SDL_Window* win;
  31.     SDL_GLContext ctx;
  32.  
  33.     int result = SDL_Init(SDL_INIT_VIDEO);
  34.     if (result < 0)
  35.         return 1;
  36.  
  37.     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  38.     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
  39.     SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
  40.     SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
  41.     SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
  42.     SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
  43.     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
  44.     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
  45.  
  46.     win = SDL_CreateWindow("Hello SDL",
  47.                            SDL_WINDOWPOS_CENTERED,
  48.                            SDL_WINDOWPOS_CENTERED,
  49.                            window_width, window_height,
  50.                            SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
  51.     if (!win)
  52.         return 2;
  53.  
  54.     ctx = SDL_GL_CreateContext(win);
  55.     SDL_GL_SetSwapInterval(1);
  56.  
  57.     SDL_Delay(1000);
  58.  
  59.     SDL_GL_DeleteContext(ctx);
  60.     SDL_DestroyWindow(win);
  61.     SDL_Quit();
  62.  
  63.     return 0;
  64. }
  65.  
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement