+ gl_extensions = "";
+ gl_platformextensions = "";
+
+ mainwindow = CreateWindowEx (ExWindowStyle, "DarkPlacesWindowClass", gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL);
+ if (!mainwindow)
+ {
+ Con_Printf("CreateWindowEx(%d, %s, %s, %d, %d, %d, %d, %d, %p, %p, %d, %p) failed\n", (int)ExWindowStyle, "DarkPlacesWindowClass", gamename, (int)WindowStyle, (int)(rect.left), (int)(rect.top), (int)(rect.right - rect.left), (int)(rect.bottom - rect.top), NULL, NULL, (int)global_hInstance, NULL);
+ VID_Shutdown();
+ return false;
+ }
+
+ baseDC = GetDC(mainwindow);
+
+ if (!newpixelformat)
+ newpixelformat = ChoosePixelFormat(baseDC, &pfd);
+ pixelformat = newpixelformat;
+ if (!pixelformat)
+ {
+ VID_Shutdown();
+ Con_Printf("ChoosePixelFormat(%d, %p) failed\n", (int)baseDC, &pfd);
+ return false;
+ }
+
+ if (SetPixelFormat(baseDC, pixelformat, &pfd) == false)
+ {
+ VID_Shutdown();
+ Con_Printf("SetPixelFormat(%d, %d, %p) failed\n", (int)baseDC, pixelformat, &pfd);
+ return false;
+ }
+
+ if (!GL_CheckExtension("wgl", wglfuncs, NULL, false))
+ {
+ VID_Shutdown();
+ Con_Print("wgl functions not found\n");
+ return false;
+ }
+
+ baseRC = qwglCreateContext(baseDC);
+ if (!baseRC)
+ {
+ VID_Shutdown();
+ Con_Print("Could not initialize GL (wglCreateContext failed).\n\nMake sure you are in 65536 color mode, and try running -window.\n");
+ return false;
+ }
+ if (!qwglMakeCurrent(baseDC, baseRC))
+ {
+ VID_Shutdown();
+ Con_Printf("wglMakeCurrent(%d, %d) failed\n", (int)baseDC, (int)baseRC);
+ return false;
+ }
+
+ if ((qglGetString = (const GLubyte* (GLAPIENTRY *)(GLenum name))GL_GetProcAddress("glGetString")) == NULL)
+ {
+ VID_Shutdown();
+ Con_Print("glGetString not found\n");
+ return false;
+ }
+ if ((qwglGetExtensionsStringARB = (const char *(WINAPI *)(HDC hdc))GL_GetProcAddress("wglGetExtensionsStringARB")) == NULL)
+ Con_Print("wglGetExtensionsStringARB not found\n");
+
+ gl_extensions = (const char *)qglGetString(GL_EXTENSIONS);
+ gl_platform = "WGL";
+ gl_platformextensions = "";
+
+ if (qwglGetExtensionsStringARB)
+ gl_platformextensions = (const char *)qwglGetExtensionsStringARB(baseDC);
+
+ if (!gl_extensions)
+ gl_extensions = "";
+ if (!gl_platformextensions)
+ gl_platformextensions = "";
+
+ // now some nice Windows pain:
+ // we have created a window, we needed one to find out if there are
+ // any multisample pixel formats available, the problem is that to
+ // actually use one of those multisample formats we now have to
+ // recreate the window (yes Microsoft OpenGL really is that bad)
+
+ if (windowpass == 0)
+ {
+ if (!GL_CheckExtension("WGL_ARB_pixel_format", wglpixelformatfuncs, "-noarbpixelformat", false) || !qwglChoosePixelFormatARB(baseDC, attribs, attribsf, 1, &newpixelformat, &numpixelformats) || !newpixelformat)
+ break;
+ // ok we got one - do it all over again with newpixelformat
+ qwglMakeCurrent(NULL, NULL);
+ qwglDeleteContext(baseRC);baseRC = 0;
+ ReleaseDC(mainwindow, baseDC);baseDC = 0;
+ // eat up any messages waiting for us
+ while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
+ {
+ TranslateMessage (&msg);
+ DispatchMessage (&msg);
+ }
+ }