From b16f5e8c07bc9d220ae556ad0552d7116bb0b9d7 Mon Sep 17 00:00:00 2001 From: zeromus Date: Wed, 6 Feb 2013 21:39:38 +0000 Subject: [PATCH] win32-try a different approach to improve new opengl initialization reliability --- desmume/src/windows/ogl.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/desmume/src/windows/ogl.cpp b/desmume/src/windows/ogl.cpp index 18ce9a0a4..1210dd07e 100644 --- a/desmume/src/windows/ogl.cpp +++ b/desmume/src/windows/ogl.cpp @@ -98,8 +98,8 @@ bool windows_opengl_init() if(oglAlreadyInit == true) return true; - GLuint PixelFormat; - static PIXELFORMATDESCRIPTOR pfd; + GLuint PixelFormat; + static PIXELFORMATDESCRIPTOR pfd; memset(&pfd,0, sizeof(PIXELFORMATDESCRIPTOR)); pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; @@ -109,18 +109,21 @@ bool windows_opengl_init() pfd.cDepthBits = 24; pfd.cAlphaBits = 8; pfd.cStencilBits = 8; - pfd.iLayerType = PFD_MAIN_PLANE ; - main_hDC = GetDC(NULL); - PixelFormat = ChoosePixelFormat(main_hDC, &pfd); - SetPixelFormat(main_hDC, PixelFormat, &pfd); - main_hRC = wglCreateContext(main_hDC); - wglMakeCurrent(main_hDC, main_hRC); + pfd.iLayerType = PFD_MAIN_PLANE; + + HWND fakeWindow = CreateWindow("EDIT", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + + main_hDC = GetDC(fakeWindow); + PixelFormat = ChoosePixelFormat(main_hDC, &pfd); + SetPixelFormat(main_hDC, PixelFormat, &pfd); + main_hRC = wglCreateContext(main_hDC); + wglMakeCurrent(main_hDC, main_hRC); int res = CheckHardwareSupport(main_hDC); if (res>=0&&res<=2) - INFO("WGL OpenGL mode: %s\n",opengl_modes[res]); - else - INFO("WGL OpenGL mode: uknown\n"); + INFO("WGL OpenGL mode: %s\n",opengl_modes[res]); + else + INFO("WGL OpenGL mode: uknown\n"); oglAlreadyInit = true;