Difference between revisions of "Creating an OpenGL Context (WGL)"
m (OpenGL 3.0 and beyond, creating a context moved to Creating an OpenGL 3.x context: Shorter, more reasonable name.)
Revision as of 04:40, 15 August 2009
In order to create a GL 3.x context (as of this writing, GL 3.1 spec is released), you need to do the following :
1. Create a window.
2. Setup the pixelformat just like you use to.
3. Create a GL context just like you use to. On Windows, wglCreateContext(hdc)
4. Make the context current. On Windows, wglMakeCurrent(hdc, glcontext)
5. Get the function pointer to wglGetExtensionsStringARB. This function is part of WGL_ARB_extensions_string. You don't need to bother to see if the extension exists. Just get the function pointer.
6. Call wglGetExtensionsStringARB(hdc), and check the returned string for WGL_ARB_create_context
7. If present, get function pointer to wglCreateContextAttribsARB
8. Kill GL context, wglMakeCurrent(NULL, NULL) and then wglDeleteContext(glcontext)
9. int attribList =
gl3context = wglCreateContextAttribsARB(hdc, 0, attribList);
10. If context creation succeeded, make current wglMakeCurrent(hdc, gl3context)
11. Call glGetString(GL_VERSION)
FINAL STEP. To destroy the GL3 context when program shuts down, wglMakeCurrent(NULL, NULL) and then wglDeleteContext(gl3context)