Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <SDL.h>
  2. #include <sdl_opengl.h>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. const float ScreenHeight = 800;
  8. const float ScreenWidth = 600;
  9. bool isFullscreen;
  10.  
  11. bool Init()
  12. {
  13.     const SDL_VideoInfo *VideoInfo = NULL;
  14.     int flags = 0;
  15.     if (SDL_Init(SDL_INIT_VIDEO) < 0)
  16.     {
  17.         fprintf(stderr, "SDL initialization failed %s\n", SDL_GetError());
  18.         return false;
  19.     }
  20.     atexit(SDL_Quit);
  21.     VideoInfo = SDL_GetVideoInfo();
  22.     if (VideoInfo == NULL)
  23.     {
  24.         fprintf(stderr, "Attempt to get video info failed %s\n", SDL_GetError());
  25.         return false;
  26.     }
  27.     flags = SDL_OPENGL;
  28.     if (isFullscreen)
  29.         flags |= SDL_FULLSCREEN;
  30.     SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
  31.     SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
  32.     SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
  33.     SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
  34.     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
  35.     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  36.  
  37.     SDL_SetVideoMode(ScreenWidth, ScreenHeight,
  38.         VideoInfo->vfmt->BitsPerPixel, flags);
  39.  
  40.     glViewport(0, 0, ScreenWidth, ScreenHeight);
  41.     glMatrixMode(GL_PROJECTION);
  42.     glLoadIdentity();
  43.     glOrtho(0.0, ScreenWidth-1.0, 0.0, ScreenHeight-1.0, 10.0, -10.0);
  44.     glMatrixMode(GL_MODELVIEW);
  45.     glLoadIdentity();
  46.     glClearColor(0.0f, 0.f, 0.0f, 1.0f);
  47.     return true;
  48. }
  49.  
  50. int main()
  51. {
  52.     Init();
  53.  
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement