diff --git a/src/Magnum/Platform/WindowlessWglApplication.cpp b/src/Magnum/Platform/WindowlessWglApplication.cpp index 6466607df..eb10cb980 100644 --- a/src/Magnum/Platform/WindowlessWglApplication.cpp +++ b/src/Magnum/Platform/WindowlessWglApplication.cpp @@ -104,14 +104,29 @@ bool WindowlessWglApplication::tryCreateContext(const Configuration& configurati const int pixelFormat = ChoosePixelFormat(_deviceContext, &pfd); SetPixelFormat(_deviceContext, pixelFormat, &pfd); - const int attributes = { + const int attributes[] = { WGL_CONTEXT_FLAGS_ARB, int(configuration.flags()), 0 }; - /* Create context and make it current */ - const PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = reinterpret_cast( wglGetProcAddress(reinterpret_cast("glXCreateContextAttribsARB"))); + /* Create temporary context so we are able to get the pointer to + wglCreateContextAttribsARB() */ + HGLRC temporaryContext = wglCreateContext(_deviceContext); + if(!wglMakeCurrent(_deviceContext, temporaryContext)) { + Error() << "Platform::WindowlessWglApplication::tryCreateContext(): cannot make temporary context current:" << GetLastError(); + return false; + } + + /* Get pointer to proper context creation function and create real context + with it */ + typedef HGLRC(WINAPI*PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC, HGLRC, const int*); + const PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = reinterpret_cast( wglGetProcAddress(reinterpret_cast("wglCreateContextAttribsARB"))); _renderingContext = wglCreateContextAttribsARB(_deviceContext, 0, attributes); + + /* Delete the temporary context */ + wglMakeCurrent(_deviceContext, nullptr); + wglDeleteContext(temporaryContext); + if(!_renderingContext) { Error() << "Platform::WindowlessWglApplication::tryCreateContext(): cannot create context:" << GetLastError(); return false; diff --git a/src/Magnum/Platform/WindowlessWglApplication.h b/src/Magnum/Platform/WindowlessWglApplication.h index 544879ed6..fbcd5a962 100644 --- a/src/Magnum/Platform/WindowlessWglApplication.h +++ b/src/Magnum/Platform/WindowlessWglApplication.h @@ -41,6 +41,11 @@ #include "Magnum/OpenGL.h" #include "Magnum/Platform/Platform.h" +/* Define stuff that we need because I can't be bothered with creating a new + header just for two defines */ +#define WGL_CONTEXT_FLAGS_ARB 0x2094 +#define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001 + namespace Magnum { namespace Platform { /** @@ -199,7 +204,6 @@ class WindowlessWglApplication::Configuration { #endif constexpr /*implicit*/ Configuration() {} - ~Configuration(); /** @brief Context flags */ Flags flags() const { return _flags; }