From c703f5b01bf5d7eeb13091e64109b58f5d12f53c Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 5 Nov 2016 17:07:59 +0200 Subject: [PATCH] Create a temporary context for calling wglGetProcAddress --- source/graphics/wgl/glcontext.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source/graphics/wgl/glcontext.cpp b/source/graphics/wgl/glcontext.cpp index 98aabb3..35ec8e9 100644 --- a/source/graphics/wgl/glcontext.cpp +++ b/source/graphics/wgl/glcontext.cpp @@ -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(wglGetProcAddress("wglCreateContextAttribs")); + ContextHandle fake_context = wglCreateContext(dc); + wglMakeCurrent(dc, fake_context); + + PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = reinterpret_cast(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); -- 2.43.0