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

From OpenGL Wiki
Jump to: navigation, search
m
m
Line 9: Line 9:
 
7. If present, get function pointer to <b>wglCreateContextAttribsARB</b><br>
 
7. If present, get function pointer to <b>wglCreateContextAttribsARB</b><br>
 
8. Kill GL context, wglMakeCurrent(NULL, NULL) and then wglDeleteContext(glcontext)<br>
 
8. Kill GL context, wglMakeCurrent(NULL, NULL) and then wglDeleteContext(glcontext)<br>
8. int attribList[] =<br>
+
9. int attribList[] =<br>
 
{<br>
 
{<br>
 
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,<br>
 
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,<br>
Line 16: Line 16:
 
0, 0};<br>
 
0, 0};<br>
 
gl3context = wglCreateContextAttribsARB(hdc, 0, attribList);
 
gl3context = wglCreateContextAttribsARB(hdc, 0, attribList);
9. If context creation succeeded, make current wglMakeCurrent(hdc, gl3context)<br>
+
10. If context creation succeeded, make current wglMakeCurrent(hdc, gl3context)<br>
10. Call glGetString(GL_VERSION)<br>
+
11. Call glGetString(GL_VERSION)<br>
 
......<br>
 
......<br>
 
FINAL STEP. To destroy the GL3 context when program shuts down, wglMakeCurrent(NULL, NULL) and then wglDeleteContext(gl3context)<br>
 
FINAL STEP. To destroy the GL3 context when program shuts down, wglMakeCurrent(NULL, NULL) and then wglDeleteContext(gl3context)<br>

Revision as of 05:30, 2 May 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[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 0,
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
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)