Skip to content

Instantly share code, notes, and snippets.

@powerc9000
Created March 25, 2016 21:50
Show Gist options
  • Save powerc9000/538ab96c471ba4edecbe to your computer and use it in GitHub Desktop.
Save powerc9000/538ab96c471ba4edecbe to your computer and use it in GitHub Desktop.
// 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