Created
          March 25, 2016 21:50 
        
      - 
      
- 
        Save powerc9000/538ab96c471ba4edecbe to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // The OpenGL libraries, make sure to include the GLUT and OpenGL frameworks | |
| #include <OpenGL/gl.h> | |
| #include <OpenGL/glu.h> | |
| #include <SDL2/SDL.h> | |
| // This is just an example using basic glut functionality. | |
| // If you want specific Apple functionality, look up AGL | |
| int main(int argc, char **argv) | |
| { | |
| SDL_Window *window = SDL_CreateWindow( | |
| "SDL2/OpenGL Demo", 0, 0, 640, 480, | |
| SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE); | |
| // Create an OpenGL context associated with the window. | |
| SDL_GLContext glcontext = SDL_GL_CreateContext(window); | |
| // now you can make GL calls. | |
| int quit = 0; | |
| int color = 1; | |
| SDL_Event event; | |
| while(!quit){ | |
| while(SDL_PollEvent(&event)) | |
| { | |
| /* If a quit event has been sent */ | |
| if (event.type == SDL_QUIT) | |
| { | |
| /* Quit the application */ | |
| quit = 1; | |
| } | |
| } | |
| glClearColor(1,0,color,0); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| glBegin(GL_TRIANGLES); | |
| glVertex3f(0.0, 0.0, -10.0); | |
| glVertex3f(1.0, 0.0, -10.0); | |
| glVertex3f(0.0, 1.0, -10.0); | |
| glEnd(); | |
| SDL_GL_SwapWindow(window); | |
| if(color == 1){ | |
| color = 0; | |
| } | |
| else{ | |
| color = 1; | |
| } | |
| SDL_Delay(500); | |
| } | |
| // Once finished with OpenGL functions, the SDL_GLContext can be deleted. | |
| SDL_GL_DeleteContext(glcontext); | |
| return 0; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment