void WGL_CreateContext(HWND hWnd, const RenderSystem::Config & config) { gWGL.hwnd = hWnd; gWGL.hdc = GetDC(hWnd); WGL_Init(); WGL_SetPixelFormat(gWGL.hdc, config); gWGL.hrc = wglCreateContext(gWGL.hdc); d_assert (gWGL.hrc != NULL); wglMakeCurrent(gWGL.hdc, gWGL.hrc); }
static int LoadGL(const char *driver) { int colorbits = Cvar_ClampInteger(gl_colorbits, 0, 32); int depthbits = Cvar_ClampInteger(gl_depthbits, 0, 32); int stencilbits = Cvar_ClampInteger(gl_stencilbits, 0, 8); int multisamples = Cvar_ClampInteger(gl_multisamples, 0, 32); int ret; // figure out if we're running on a minidriver or not if (!Q_stricmp(driver, "opengl32") || !Q_stricmp(driver, "opengl32.dll")) { glw.minidriver = qfalse; } else { Com_Printf("...running a minidriver: %s\n", driver); glw.minidriver = qtrue; } // load the OpenGL library and bind to it if (!WGL_Init(driver)) { ReportLastError("WGL_Init"); return FAIL_SOFT; } // check if basic WGL entry points are present if (!qwglCreateContext || !qwglMakeCurrent || !qwglDeleteContext) { Com_EPrintf("Required WGL entry points are missing\n"); goto fail; } if (glw.minidriver) { // check if MCD entry points are present if using a minidriver if (!qwglChoosePixelFormat || !qwglSetPixelFormat || !qwglDescribePixelFormat || !qwglSwapBuffers) { Com_EPrintf("Required MCD entry points are missing\n"); goto fail; } } // check for WGL_ARB_multisample by creating a fake window if (multisamples > 1) { unsigned extensions = GetFakeWindowExtensions(); if (extensions & QWGL_ARB_multisample) { if (qwglChoosePixelFormatARB) { Com_Printf("...enabling WGL_ARB_multisample\n"); } else { Com_Printf("...ignoring WGL_ARB_multisample, WGL_ARB_pixel_format not found\n"); Cvar_Set("gl_multisamples", "0"); multisamples = 0; } } else { Com_Printf("WGL_ARB_multisample not found\n"); Cvar_Set("gl_multisamples", "0"); multisamples = 0; } } // create window, choose PFD, setup OpenGL context ret = SetupGL(colorbits, depthbits, stencilbits, multisamples); // attempt to recover if (ret == FAIL_SOFT && (colorbits || depthbits || stencilbits || multisamples > 1)) { Cvar_Set("gl_multisamples", "0"); ret = SetupGL(0, 0, 0, 0); } if (ret) goto fail; return FAIL_OK; fail: // it failed, clean up WGL_Shutdown(); return FAIL_SOFT; }