Thursday 23 August 2012

SDL2.0 to create a modern OpenGL context.

I've been having difficulty finding documentation for SDL2.0 so I'm going to record the invocations here as I find them... (With thanks to everyone who's helped me find them)

Once I've got a better (and full) handle on it I might try to right a well written tutorial... For now I'll just record my findings.

Requesting a given version of OpenGL

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,2);

This appears to disable the compatibility profile/enable the core profile only. I need to check this though.

Creating an OpenGL context...

int width = 640; int height = 480;
SDL_Window* pWindow;
SDL_GLContext context;
int other_flags = 0;

pWindow = SDL_CreateWindow("Title", 
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 
width, height, 
SDL_WINDOW_OPENGL|other_flags);

context = SDL_GL_CreateContext(pWindow);

Verifying that the Context was created successfully...

const unsigned char* version = glGetString(GL_VERSION);
if (version == NULL) {
// Failed to initialise, error logging here
exit(-1);
}

Flushing pipeline...

SDL_GL_SwapWindow(pWindow);

Todo: Figure out how to compile/link a shader.



No comments:

Post a Comment