Skip to content

Instantly share code, notes, and snippets.

@blackwolf12333
Created January 10, 2015 20:11
Show Gist options
  • Save blackwolf12333/aacc963a61168a6f0908 to your computer and use it in GitHub Desktop.
Save blackwolf12333/aacc963a61168a6f0908 to your computer and use it in GitHub Desktop.
just the initGL function
void Main::initGL() {
/* Request opengl 3.2 context.
* SDL doesn't have the ability to choose which profile at this time of writing,
* but it should default to the core profile */
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
/* Turn on double buffering with a 24bit Z buffer.
* You may need to change this to 16 or 32 for your system */
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);
glViewport(0.0, 0.0, SCREEN_WIDTH, SCREEN_HEIGHT);
glOrtho( 0.0, SCREEN_WIDTH, SCREEN_HEIGHT, 0.0, 1.0, -1.0 );
glContext = SDL_GL_CreateContext(this->window);
SDL_GL_SetSwapInterval(0);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
//Initialize clear color
glClearColor( 0.f, 0.f, 0.f, 1.f );
//Enable texturing
glEnable( GL_TEXTURE_2D );
glEnable(GL_TEXTURE_RECTANGLE_ARB);
//Check for error
GLenum error = glGetError();
if(error != GL_NO_ERROR) {
printf("Error initializing OpenGL!\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment