Here's a modern day OpenGL context creation on Windows. It's a goddamn mess, because you have to create a context to ask what kind of context you can create. But that's how it's set up. You will probably want to read the documentation page for WGL_ARB_create_context for all the gross details.
//Create a basic OpenGL context
g_hRC = wglCreateContext(g_hDC);
if(!g_hRC)
{
GlobalLogger->Write(LP_Critical, "Failed to create any OpenGL context at all.");
KillGraphics();
return false;
}
wglMakeCurrent(g_hDC, g_hRC);
//Attempt to create a new GL 3.0+ context
int flags = 0;
int profile = WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
if(ap_OpenGLForwardCompat)
flags |= WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
if(ap_GraphicsDebug)
flags |= WGL_CONTEXT_DEBUG_BIT_ARB;
if(ap_OpenGLCompat)
profile = WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
glewInit();
if(wglewIsSupported("WGL_ARB_create_context"))
{
int attribs[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, ap_OpenGLMajorVersion,
WGL_CONTEXT_MINOR_VERSION_ARB, ap_OpenGLMinorVersion,
WGL_CONTEXT_FLAGS_ARB, flags,
WGL_CONTEXT_PROFILE_MASK_ARB, profile,
0
};
//New context is available, spool it up and destroy the old one
wglMakeCurrent(NULL, NULL);
wglDeleteContext(g_hRC);
g_hRC = wglCreateContextAttribsARB(g_hDC, 0, attribs);
if(!g_hRC)
{
logger.WriteFormat(LP_Critical, "Failed to create OpenGL %d.%d context.", ap_OpenGLMajorVersion, ap_OpenGLMinorVersion);
KillGraphics();
return false;
}
wglMakeCurrent(g_hDC, g_hRC);
glGetIntegerv(GL_MAJOR_VERSION, &ap_OpenGLMajorVersion);
glGetIntegerv(GL_MINOR_VERSION, &ap_OpenGLMinorVersion);
logger.WriteFormat(LP_Info, "Created OpenGL context version: %d.%d%s", ap_OpenGLMajorVersion, ap_OpenGLMinorVersion,
ap_OpenGLCompat ? " (compatibility)" : "");
}
else
{
logger.WriteFormat(LP_Warning, "Using OpenGL legacy context version: %s", glGetString(GL_VERSION));
}