]> git.tdb.fi Git - libs/gui.git/commitdiff
Create a temporary context for calling wglGetProcAddress
authorMikko Rasa <tdb@tdb.fi>
Sat, 5 Nov 2016 15:07:59 +0000 (17:07 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 5 Nov 2016 15:07:59 +0000 (17:07 +0200)
source/graphics/wgl/glcontext.cpp

index 98aabb310abb99f95356a6000f8997587d426ee6..35ec8e9b1983471f5dd12e476f4a662d2deaa7c4 100644 (file)
@@ -45,7 +45,10 @@ void GLContext::platform_init(const GLOptions &opts)
        priv = new Private;
        if(opts.forward_compatible || opts.gl_version_major)
        {
-               PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = reinterpret_cast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(wglGetProcAddress("wglCreateContextAttribs"));
+               ContextHandle fake_context = wglCreateContext(dc);
+               wglMakeCurrent(dc, fake_context);
+
+               PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = reinterpret_cast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(wglGetProcAddress("wglCreateContextAttribsARB"));
                if(!wglCreateContextAttribs)
                        throw unsupported_gl_mode(opts);
 
@@ -68,6 +71,11 @@ void GLContext::platform_init(const GLOptions &opts)
                ctx_attribs.push_back(0);
 
                priv->context = wglCreateContextAttribs(dc, 0, &ctx_attribs[0]);
+               if(!priv->context)
+                       throw unsupported_gl_mode(opts);
+
+               wglMakeCurrent(0, 0);
+               wglDeleteContext(fake_context);
        }
        else
                priv->context = wglCreateContext(dc);