konalisp

the_screams_of_one_million_chimps_in_agony_recordedlive.flac

Sep 22nd, 2014
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.51 KB | None | 0 0
  1. //Compile with: clang++ *.cxx -w -lGL -lSDL2 -lSDL2main -ldl -o main
  2.  
  3. #include <SDL2/SDL.h>
  4. #include <SDL2/SDL_opengl.h>
  5. #include <GL/gl.h>
  6. #include <iostream>
  7.  
  8. using namespace std;
  9.  
  10. #define PROGRAM_NAME "Try Kind Of Hard"
  11. void checkSDLError()
  12. {
  13. #ifndef NDEBUG
  14.     const char *error = SDL_GetError();
  15.     if (*error != '\0')
  16.     {
  17.         cout << "SDL Error: " << error << "\n";
  18.         SDL_ClearError();
  19.     }
  20. #endif
  21. }
  22.  
  23. int main(int argc, char** argv){
  24.     SDL_Window *mainwindow; /* Our window handle */
  25.     SDL_GLContext maincontext; /* Our opengl context handle */
  26.  
  27.     if (SDL_Init(SDL_INIT_VIDEO) < 0) { /* Initialize SDL's Video subsystem */
  28.         SDL_Quit();
  29.         exit(1);
  30.     }
  31.     /* Request opengl 3.2 context.
  32.      * SDL doesn't have the ability to choose which profile at this time of writing,
  33.      * but it should default to the core profile */
  34.     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
  35.  
  36.     /* Turn on double buffering with a 24bit Z buffer.
  37.      * You may need to change this to 16 or 32 for your system */
  38.     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  39.     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
  40.  
  41.     /* Create our window centered at 512x512 resolution */
  42.     mainwindow = SDL_CreateWindow(PROGRAM_NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
  43.         512, 512, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
  44.     if (!mainwindow) { /* Die if creation failed */
  45.         SDL_Quit();
  46.         exit(1);
  47.     }
  48.     checkSDLError();
  49.  
  50.     /* Create our opengl context and attach it to our window */
  51.     maincontext = SDL_GL_CreateContext(mainwindow);
  52.     checkSDLError();
  53.  
  54.  
  55.     /* This makes our buffer swap syncronized with the monitor's vertical refresh */
  56.     SDL_GL_SetSwapInterval(1);
  57.  
  58.     /* Clear our buffer with a red background */
  59.     glClearColor ( 1.0, 0.0, 0.0, 1.0 );
  60.     glClear ( GL_COLOR_BUFFER_BIT );
  61.     /* Swap our back buffer to the front */
  62.     SDL_GL_SwapWindow(mainwindow);
  63.     /* Wait 2 seconds */
  64.     SDL_Delay(2000);
  65.  
  66.     /* Same as above, but green */
  67.     glClearColor ( 0.0, 1.0, 0.0, 1.0 );
  68.     glClear ( GL_COLOR_BUFFER_BIT );
  69.     SDL_GL_SwapWindow(mainwindow);
  70.     SDL_Delay(2000);
  71.  
  72.     /* Same as above, but blue */
  73.     glClearColor ( 0.0, 0.0, 1.0, 1.0 );
  74.     glClear ( GL_COLOR_BUFFER_BIT );
  75.     SDL_GL_SwapWindow(mainwindow);
  76.     SDL_Delay(2000);
  77.  
  78.     /* Delete our opengl context, destroy our window, and shutdown SDL */
  79.     SDL_GL_DeleteContext(maincontext);
  80.     SDL_DestroyWindow(mainwindow);
  81.     SDL_Quit();
  82.  
  83.     return 0;
  84. }
Add Comment
Please, Sign In to add comment