From 176a72653e73da9d63c1cf0faaeae03cb58c9881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 3 Aug 2016 11:02:43 +0200 Subject: [PATCH] Platform: update WindowlessWindowsEglContext to match the WglContext. Applied 78ddfad54330619585b6819ce548fd8124ebfde2 on this class. Also fixed suspicious window creation -- the private member variable was never initialized. --- .../WindowlessWindowsEglApplication.cpp | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/Magnum/Platform/WindowlessWindowsEglApplication.cpp b/src/Magnum/Platform/WindowlessWindowsEglApplication.cpp index cf4c944e3..137959aa9 100644 --- a/src/Magnum/Platform/WindowlessWindowsEglApplication.cpp +++ b/src/Magnum/Platform/WindowlessWindowsEglApplication.cpp @@ -36,25 +36,34 @@ namespace Magnum { namespace Platform { WindowlessWindowsEglContext::WindowlessWindowsEglContext(const Configuration& configuration, Context*) { + /* Register the window class (if not yet done) */ + WNDCLASSW wc; + if(!GetClassInfoW(GetModuleHandleW(nullptr), L"Magnum Windowless Application", &wc)) { + wc = WNDCLASSW{ + 0, + DefWindowProcW, + 0, + 0, + GetModuleHandleW(nullptr), + nullptr, + nullptr, + HBRUSH(COLOR_BACKGROUND), + nullptr, + L"Magnum Windowless Application" + }; + + if(!RegisterClassW(&wc)) { + Error() << "Platform::WindowlessWglContext: cannot create window class:" << GetLastError(); + return; + } + } + /* Create the window */ - const WNDCLASS wc{ - 0, - DefWindowProc, - 0, - 0, - GetModuleHandle(nullptr), - nullptr, - nullptr, - HBRUSH(COLOR_BACKGROUND), - nullptr, - L"Magnum Windowless Application" - }; - if(!RegisterClass(&wc)) return; - const HWND window = CreateWindowW(wc.lpszClassName, L"Magnum Windowless Application", + _window = CreateWindowW(wc.lpszClassName, L"Magnum Windowless Application", WS_OVERLAPPEDWINDOW, 0, 0, 32, 32, 0, 0, wc.hInstance, 0); /* Initialize */ - _display = eglGetDisplay(GetDC(window)); + _display = eglGetDisplay(GetDC(_window)); if(!eglInitialize(_display, nullptr, nullptr)) { Error() << "Platform::WindowlessWindowsEglApplication::tryCreateContext(): cannot initialize EGL:" << Implementation::eglErrorString(eglGetError()); return false;