Advertisement
Guest User

Untitled

a guest
May 29th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <SDL2/SDL.h>
  3. #define GL3_PROTOTYPES 1
  4. #include <GL3/gl3.h>
  5.  
  6. int main(int argc, char **argv) {
  7.     SDL_Window *window(0);
  8.     SDL_GLContext glcontext;
  9.  
  10.     SDL_Init(SDL_INIT_VIDEO);
  11.  
  12.     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
  13.     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
  14.  
  15.     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  16.     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
  17.  
  18.     window = SDL_CreateWindow("OpenGL", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 360, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
  19.     glcontext = SDL_GL_CreateContext(window);
  20.  
  21.  
  22.     float vertices[] = {-0.5, -0.5,   0.0, 0.5,   0.5, -0.5};
  23.  
  24.     glClear(GL_COLOR_BUFFER_BIT);
  25.  
  26.     glEnableVertexAttribArray(0);
  27.     glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices);
  28.  
  29.     glDrawArrays(GL_TRIANGLES, 0, 3);
  30.     glDisableVertexAttribArray(0);
  31.  
  32.     SDL_GL_SwapWindow(window);
  33.  
  34.  
  35.     SDL_Event events;
  36.     bool close(false);
  37.     while(!close) {
  38.         SDL_WaitEvent(&events);
  39.         if((events.type == SDL_KEYDOWN && events.key.keysym.sym == SDLK_ESCAPE) || events.type == SDL_QUIT)
  40.             close = true;
  41.     }
  42.  
  43.     SDL_GL_DeleteContext(glcontext);
  44.     SDL_DestroyWindow(window);
  45.     SDL_Quit();
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement