Creating an OpenGL Context (WGL)

From OpenGL Wiki
Revision as of 05:29, 2 May 2009 by V-man (talk | contribs)
Jump to navigation Jump to search

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)
8. int attribList[] =
0, 0};
gl3context = wglCreateContextAttribsARB(hdc, 0, attribList); 9. If context creation succeeded, make current wglMakeCurrent(hdc, gl3context)
10. Call glGetString(GL_VERSION)
FINAL STEP. To destroy the GL3 context when program shuts down, wglMakeCurrent(NULL, NULL) and then wglDeleteContext(gl3context)