Created
February 11, 2015 04:43
-
-
Save tpdns90321/0f42540b61351d02ebae to your computer and use it in GitHub Desktop.
SDL2_Opengl Example
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
#include<SDL2/SDL.h> | |
#include<SDL2/SDL_opengl.h> | |
#include<GL/glut.h> | |
int main(){ | |
//Create window | |
SDL_Window *window = SDL_CreateWindow("Test",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,640,480,SDL_WINDOW_OPENGL); | |
//OpenGL Init | |
SDL_GLContext context = SDL_GL_CreateContext(window); | |
glMatrixMode(GL_MODELVIEW); | |
glLoadIdentity(); | |
glClear(GL_COLOR_BUFFER_BIT); | |
//Make Polygon | |
glBegin(GL_QUADS); | |
glColor3f(255,255,255); | |
glVertex2f(0.5,0.5); | |
glVertex2f(0.5,-0.5); | |
glVertex2f(-0.5,-0.5); | |
glVertex2f(-0.5,0.5); | |
glEnd(); | |
//OpenGL Update | |
SDL_GL_SwapWindow(window); | |
//Other SDL instructions | |
SDL_Delay(5000); | |
//Free space and SDL Quit | |
SDL_GL_DeleteContext(context); | |
SDL_DestroyWindow(window); | |
SDL_Quit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment