Difference between revisions of "Creating an OpenGL Context (WGL)"

From OpenGL Wiki
Jump to navigation Jump to search
m (Creating an OpenGL 3.x context moved to Creating an OpenGL Context: This is, or will be, about all aspects of context creation, not just GL 3.x versions)
(No difference)

Revision as of 18:32, 19 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[] =
0, 0};
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)