static int GLW_MakeContext( PIXELFORMATDESCRIPTOR *pPFD ) { // // don't putz around with pixelformat if it's already set (e.g. this is a soft // reset of the graphics system) // if ( !glw_state.pixelFormatSet ) { int pixelformat; // // choose, set, and describe our desired pixel format. If we're // using a minidriver then we need to bypass the GDI functions, // otherwise use the GDI functions. // if (glw_state.nPendingPF) pixelformat = glw_state.nPendingPF; else if ( ( pixelformat = GLW_ChoosePFD( glw_state.hDC, pPFD ) ) == 0 ) { ri.Printf( PRINT_ALL, "...GLW_ChoosePFD failed\n"); return TRY_PFD_FAIL_SOFT; } ri.Printf( PRINT_DEVELOPER, "...PIXELFORMAT %d selected\n", pixelformat ); DescribePixelFormat( glw_state.hDC, pixelformat, sizeof( *pPFD ), pPFD ); if ( SetPixelFormat( glw_state.hDC, pixelformat, pPFD ) == FALSE ) { ri.Printf( PRINT_ALL, "...SetPixelFormat failed\n", glw_state.hDC ); return TRY_PFD_FAIL_SOFT; } glw_state.pixelFormatSet = qtrue; } // // startup the OpenGL subsystem by creating a context and making it current // if ( !glw_state.hGLRC ) { if ( ( glw_state.hGLRC = qwglCreateContext( glw_state.hDC ) ) == 0 ) { ri.Printf( PRINT_ALL, "...GL context creation failure\n" ); return TRY_PFD_FAIL_HARD; } ri.Printf( PRINT_DEVELOPER, "...GL context created\n" ); if ( !qwglMakeCurrent( glw_state.hDC, glw_state.hGLRC ) ) { qwglDeleteContext( glw_state.hGLRC ); glw_state.hGLRC = NULL; ri.Printf( PRINT_ALL, "...GL context creation currency failure\n" ); return TRY_PFD_FAIL_HARD; } ri.Printf( PRINT_DEVELOPER, "...GL context creation made current\n" ); } return TRY_PFD_SUCCESS; }
/* ** GLimp_Shutdown ** ** This routine does all OS specific shutdown procedures for the OpenGL ** subsystem. Under OpenGL this means NULLing out the current DC and ** HGLRC, deleting the rendering context, and releasing the DC acquired ** for the window. The state structure is also nulled out. ** */ void GLimp_Shutdown( void ) { if ( qwglMakeCurrent && !qwglMakeCurrent( NULL, NULL ) ) Com_Printf ( "GLimp_Shutdown() - wglMakeCurrent failed\n"); if ( glw_state.hGLRC ) { if ( qwglDeleteContext && !qwglDeleteContext( glw_state.hGLRC ) ) Com_Printf ( "GLimp_Shutdown() - wglDeleteContext failed\n"); glw_state.hGLRC = NULL; } if (glw_state.hDC) { if ( !ReleaseDC( glw_state.hWnd, glw_state.hDC ) ) Com_Printf ( "GLimp_Shutdown() - ReleaseDC failed\n" ); glw_state.hDC = NULL; } if (glw_state.hWnd) { ShowWindow (glw_state.hWnd, SW_HIDE); DestroyWindow ( glw_state.hWnd ); glw_state.hWnd = NULL; } UnregisterClass (WINDOW_CLASS_NAME, glw_state.hInstance); s_classRegistered = false; if ( gl_state.fullscreen ) { ChangeDisplaySettings( 0, 0 ); gl_state.fullscreen = false; } }
/* ** GLimp_Shutdown ** ** This routine does all OS specific shutdown procedures for the OpenGL ** subsystem. Under OpenGL this means NULLing out the current DC and ** HGLRC, deleting the rendering context, and releasing the DC acquired ** for the window. The state structure is also nulled out. ** */ void GLimp_Shutdown( void ) { if( glw_state.parenthWnd ) PostMessage( glw_state.parenthWnd, UWM_APPACTIVE, WA_INACTIVE, 0 ); if( qwglMakeCurrent && !qwglMakeCurrent( NULL, NULL ) ) Com_Printf( "ref_gl::R_Shutdown() - wglMakeCurrent failed\n" ); if( glw_state.hGLRC ) { if( qwglDeleteContext && !qwglDeleteContext( glw_state.hGLRC ) ) Com_Printf( "ref_gl::R_Shutdown() - wglDeleteContext failed\n" ); glw_state.hGLRC = NULL; } if( glw_state.hDC ) { if( !ReleaseDC( glw_state.hWnd, glw_state.hDC ) ) Com_Printf( "ref_gl::R_Shutdown() - ReleaseDC failed\n" ); glw_state.hDC = NULL; } if( glw_state.hWnd ) { ShowWindow( glw_state.hWnd, SW_HIDE ); DestroyWindow( glw_state.hWnd ); glw_state.hWnd = NULL; } UnregisterClass( WINDOW_CLASS_NAME, glw_state.hInstance ); if( glState.fullScreen ) { ChangeDisplaySettings( 0, 0 ); glState.fullScreen = qfalse; } }
static void GLW_AttemptFSAA() { static const float ar[] = { 0, 0 }; // ignore r_xyzbits vars - FSAA requires 32-bit color, and anyone using it is implicitly on decent HW static int anAttributes[] = { WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, WGL_SUPPORT_OPENGL_ARB, GL_TRUE, WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, WGL_DOUBLE_BUFFER_ARB, GL_TRUE, WGL_COLOR_BITS_ARB, 32, WGL_ALPHA_BITS_ARB, 0, WGL_DEPTH_BITS_ARB, 24, WGL_STENCIL_BITS_ARB, 8, WGL_SAMPLE_BUFFERS_ARB, GL_TRUE, WGL_SAMPLES_ARB, 4, 0, 0 }; qwglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)qwglGetProcAddress( "wglChoosePixelFormatARB" ); if (!r_ext_multisample->integer || !qwglChoosePixelFormatARB) { glDisable(GL_MULTISAMPLE_ARB); return; } int iPFD; UINT cPFD; anAttributes[19] = r_ext_multisample->integer; // !!! UGH if (!qwglChoosePixelFormatARB(glw_state.hDC, anAttributes, ar, 1, &iPFD, &cPFD) || !cPFD) return; // now bounce the ENTIRE f*****g subsystem thanks to WGL stupidity // we can't use GLimp_Shutdown() for this, because that does CDS poking that we don't want assert( glw_state.hGLRC && glw_state.hDC && g_wv.hWnd ); qwglMakeCurrent( glw_state.hDC, NULL ); if ( glw_state.hGLRC ) { qwglDeleteContext( glw_state.hGLRC ); glw_state.hGLRC = NULL; } if ( glw_state.hDC ) { ReleaseDC( g_wv.hWnd, glw_state.hDC ); glw_state.hDC = NULL; } if ( g_wv.hWnd ) { DestroyWindow( g_wv.hWnd ); g_wv.hWnd = NULL; } ri.Printf( PRINT_ALL, "...enabling FSAA\n" ); glw_state.nPendingPF = iPFD; glw_state.pixelFormatSet = qfalse; GLW_CreateWindow( glConfig.vidWidth, glConfig.vidHeight, glConfig.colorBits ); glw_state.nPendingPF = 0; glEnable(GL_MULTISAMPLE_ARB); }
/* ** GLimp_Shutdown ** ** This routine does all OS specific shutdown procedures for the OpenGL ** subsystem. Under OpenGL this means NULLing out the current DC and ** HGLRC, deleting the rendering context, and releasing the DC acquired ** for the window. The state structure is also nulled out. ** */ void GLimp_Shutdown( void ) { if( qwglMakeCurrent && !qwglMakeCurrent( NULL, NULL ) ) ri.Com_Printf( "ref_gl::R_Shutdown() - wglMakeCurrent failed\n" ); if( glw_state.hGLRC ) { if( qwglDeleteContext && !qwglDeleteContext( glw_state.hGLRC ) ) ri.Com_Printf( "ref_gl::R_Shutdown() - wglDeleteContext failed\n" ); glw_state.hGLRC = NULL; } if( glw_state.hDC ) { if( !ReleaseDC( glw_state.hWnd, glw_state.hDC ) ) ri.Com_Printf( "ref_gl::R_Shutdown() - ReleaseDC failed\n" ); glw_state.hDC = NULL; } if( glw_state.hWnd ) { ShowWindow( glw_state.hWnd, SW_HIDE ); DestroyWindow( glw_state.hWnd ); glw_state.hWnd = NULL; } #ifdef WITH_UTF8 UnregisterClassW( glw_state.windowClassNameW, glw_state.hInstance ); #else UnregisterClass( glw_state.windowClassName, glw_state.hInstance ); #endif if( glConfig.fullScreen ) { ChangeDisplaySettings( 0, 0 ); glConfig.fullScreen = false; } if( glw_state.applicationName ) { free( glw_state.applicationName ); glw_state.applicationName = NULL; } if( glw_state.applicationNameW ) { free( glw_state.applicationNameW ); glw_state.applicationNameW = NULL; } glw_state.applicationIconResourceID = 0; glw_state.win_x = 0; glw_state.win_y = 0; glConfig.width = 0; glConfig.height = 0; }
/* =================== GLimp_Shutdown This routine does all OS specific shutdown procedures for the OpenGL subsystem. =================== */ void GLimp_Shutdown( void ) { const char *success[] = { "failed", "success" }; int retVal; common->Printf( "Shutting down OpenGL subsystem\n" ); // set current context to NULL if ( qwglMakeCurrent ) { retVal = qwglMakeCurrent( NULL, NULL ) != 0; common->Printf( "...wglMakeCurrent( NULL, NULL ): %s\n", success[retVal] ); } // delete HGLRC if ( win32.hGLRC ) { retVal = qwglDeleteContext( win32.hGLRC ) != 0; common->Printf( "...deleting GL context: %s\n", success[retVal] ); win32.hGLRC = NULL; } // release DC if ( win32.hDC ) { retVal = ReleaseDC( win32.hWnd, win32.hDC ) != 0; common->Printf( "...releasing DC: %s\n", success[retVal] ); win32.hDC = NULL; } // destroy window if ( win32.hWnd ) { common->Printf( "...destroying window\n" ); ShowWindow( win32.hWnd, SW_HIDE ); DestroyWindow( win32.hWnd ); win32.hWnd = NULL; } // reset display settings if ( win32.cdsFullscreen ) { common->Printf( "...resetting display\n" ); ChangeDisplaySettings( 0, 0 ); win32.cdsFullscreen = false; } // close the thread so the handle doesn't dangle if ( win32.renderThreadHandle ) { common->Printf( "...closing smp thread\n" ); CloseHandle( win32.renderThreadHandle ); win32.renderThreadHandle = NULL; } // restore gamma GLimp_RestoreGamma(); // shutdown QGL subsystem QGL_Shutdown(); }
/* ** GLimp_Shutdown ** ** This routine does all OS specific shutdown procedures for the OpenGL ** subsystem. Under OpenGL this means NULLing out the current DC and ** HGLRC, deleting the rendering context, and releasing the DC acquired ** for the window. The state structure is also nulled out. ** */ void GLimp_Shutdown( void ) { if ( qwglMakeCurrent && !qwglMakeCurrent( NULL, NULL ) ) ri.Con_Printf( PRINT_ALL, "ref_gl::R_Shutdown() - wglMakeCurrent failed\n"); if ( glw_state.hGLRC ) { if ( qwglDeleteContext && !qwglDeleteContext( glw_state.hGLRC ) ) ri.Con_Printf( PRINT_ALL, "ref_gl::R_Shutdown() - wglDeleteContext failed\n"); glw_state.hGLRC = NULL; } if (glw_state.hDC) { if ( !ReleaseDC( glw_state.hWnd, glw_state.hDC ) ) ri.Con_Printf( PRINT_ALL, "ref_gl::R_Shutdown() - ReleaseDC failed\n" ); glw_state.hDC = NULL; } #ifndef __WXWINDOWS__ if (glw_state.hWnd) { DestroyWindow ( glw_state.hWnd ); glw_state.hWnd = NULL; } #endif // ndef __WXWINDOWS__ if ( glw_state.log_fp ) { fclose( glw_state.log_fp ); glw_state.log_fp = 0; } #ifndef __WXWINDOWS__ UnregisterClass (WINDOW_CLASS_NAME, glw_state.hInstance); #endif // ndef __WXWINDOWS__ if ( gl_state.fullscreen ) { ChangeDisplaySettings( 0, 0 ); gl_state.fullscreen = false; } }
/* VID_Shutdown This routine does all OS specific shutdown procedures for the OpenGL subsystem. Under OpenGL this means NULLing out the current DC and HGLRC, deleting the rendering context, and releasing the DC acquired for the window. The state structure is also nulled out. */ void VID_Shutdown(void) { if (qwglMakeCurrent) { qwglMakeCurrent(NULL, NULL); } if (glw.hGLRC && qwglDeleteContext) { qwglDeleteContext(glw.hGLRC); glw.hGLRC = NULL; } WGL_Shutdown(); Win_Shutdown(); if (gl_swapinterval) { gl_swapinterval->changed = NULL; } if (gl_drawbuffer) { gl_drawbuffer->changed = NULL; } memset(&glw, 0, sizeof(glw)); }
static unsigned GetFakeWindowExtensions(void) { WNDCLASSEX wc; PIXELFORMATDESCRIPTOR pfd; int pixelformat; HWND wnd; HDC dc; HGLRC rc; unsigned extensions = 0; memset(&wc, 0, sizeof(wc)); wc.cbSize = sizeof(wc); wc.lpfnWndProc = DefWindowProc; wc.hInstance = hGlobalInstance; wc.lpszClassName = FAKE_WINDOW_CLASS; if (!RegisterClassEx(&wc)) goto fail0; wnd = CreateWindow( FAKE_WINDOW_CLASS, FAKE_WINDOW_NAME, 0, 0, 0, 0, 0, NULL, NULL, hGlobalInstance, NULL); if (!wnd) goto fail1; if ((dc = GetDC(wnd)) == NULL) goto fail2; memset(&pfd, 0, sizeof(pfd)); pfd.nSize = sizeof(pfd); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 24; pfd.cDepthBits = 24; pfd.cStencilBits = 8; pfd.iLayerType = PFD_MAIN_PLANE; if (glw.minidriver) { if ((pixelformat = qwglChoosePixelFormat(dc, &pfd)) == 0) goto fail3; if (qwglSetPixelFormat(dc, pixelformat, &pfd) == FALSE) goto fail3; } else { if ((pixelformat = ChoosePixelFormat(dc, &pfd)) == 0) goto fail3; if (SetPixelFormat(dc, pixelformat, &pfd) == FALSE) goto fail3; } if ((rc = qwglCreateContext(dc)) == NULL) goto fail3; if (qwglMakeCurrent(dc, rc) == FALSE) goto fail4; WGL_InitExtensions(QWGL_ARB_extensions_string); if (!qwglGetExtensionsStringARB) goto fail5; extensions = WGL_ParseExtensionString(qwglGetExtensionsStringARB(dc)); if (extensions & QWGL_ARB_pixel_format) { Com_Printf("...enabling WGL_ARB_pixel_format\n"); WGL_InitExtensions(QWGL_ARB_pixel_format); } fail5: qwglMakeCurrent(NULL, NULL); fail4: qwglDeleteContext(rc); fail3: ReleaseDC(wnd, dc); fail2: DestroyWindow(wnd); fail1: UnregisterClass(FAKE_WINDOW_CLASS, hGlobalInstance); fail0: return extensions; }
/* ** GLimp_SharedContext_Destroy */ void GLimp_SharedContext_Destroy( void *context, void *surface ) { if( qwglDeleteContext ) { qwglDeleteContext( context ); } }
/* ==================== GLW_InitDriver Set the pixelformat for the window before it is shown, and create the rendering context ==================== */ static bool GLW_InitDriver( glimpParms_t parms ) { PIXELFORMATDESCRIPTOR src = { sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd 1, // version number PFD_DRAW_TO_WINDOW | // support window PFD_SUPPORT_OPENGL | // support OpenGL PFD_DOUBLEBUFFER, // double buffered PFD_TYPE_RGBA, // RGBA type 32, // 32-bit color depth 0, 0, 0, 0, 0, 0, // color bits ignored 8, // 8 bit destination alpha 0, // shift bit ignored 0, // no accumulation buffer 0, 0, 0, 0, // accum bits ignored 24, // 24-bit z-buffer 8, // 8-bit stencil buffer 0, // no auxiliary buffer PFD_MAIN_PLANE, // main layer 0, // reserved 0, 0, 0 // layer masks ignored }; common->Printf( "Initializing OpenGL driver\n" ); // // get a DC for our window if we don't already have one allocated // if ( win32.hDC == NULL ) { common->Printf( "...getting DC: " ); if ( ( win32.hDC = GetDC( win32.hWnd ) ) == NULL ) { common->Printf( "^3failed^0\n" ); return false; } common->Printf( "succeeded\n" ); } // the multisample path uses the wgl if ( wglChoosePixelFormatARB && parms.multiSamples > 1 ) { int iAttributes[20]; FLOAT fAttributes[] = {0, 0}; UINT numFormats; // FIXME: specify all the other stuff iAttributes[0] = WGL_SAMPLE_BUFFERS_ARB; iAttributes[1] = 1; iAttributes[2] = WGL_SAMPLES_ARB; iAttributes[3] = parms.multiSamples; iAttributes[4] = WGL_DOUBLE_BUFFER_ARB; iAttributes[5] = TRUE; iAttributes[6] = WGL_STENCIL_BITS_ARB; iAttributes[7] = 8; iAttributes[8] = WGL_DEPTH_BITS_ARB; iAttributes[9] = 24; iAttributes[10] = WGL_RED_BITS_ARB; iAttributes[11] = 8; iAttributes[12] = WGL_BLUE_BITS_ARB; iAttributes[13] = 8; iAttributes[14] = WGL_GREEN_BITS_ARB; iAttributes[15] = 8; iAttributes[16] = WGL_ALPHA_BITS_ARB; iAttributes[17] = 8; iAttributes[18] = 0; iAttributes[19] = 0; wglChoosePixelFormatARB( win32.hDC, iAttributes, fAttributes, 1, &win32.pixelformat, &numFormats ); } else { // this is the "classic" choose pixel format path // eventually we may need to have more fallbacks, but for // now, ask for everything if ( parms.stereo ) { common->Printf( "...attempting to use stereo\n" ); src.dwFlags |= PFD_STEREO; } // // choose, set, and describe our desired pixel format. If we're // using a minidriver then we need to bypass the GDI functions, // otherwise use the GDI functions. // if ( ( win32.pixelformat = ChoosePixelFormat( win32.hDC, &src ) ) == 0 ) { common->Printf( "...^3GLW_ChoosePFD failed^0\n"); return false; } common->Printf( "...PIXELFORMAT %d selected\n", win32.pixelformat ); } // get the full info DescribePixelFormat( win32.hDC, win32.pixelformat, sizeof( win32.pfd ), &win32.pfd ); glConfig.colorBits = win32.pfd.cColorBits; glConfig.depthBits = win32.pfd.cDepthBits; glConfig.stencilBits = win32.pfd.cStencilBits; // XP seems to set this incorrectly if ( !glConfig.stencilBits ) { glConfig.stencilBits = 8; } // the same SetPixelFormat is used either way if ( SetPixelFormat( win32.hDC, win32.pixelformat, &win32.pfd ) == FALSE ) { common->Printf( "...^3SetPixelFormat failed^0\n", win32.hDC ); return false; } // // startup the OpenGL subsystem by creating a context and making it current // common->Printf( "...creating GL context: " ); if ( ( win32.hGLRC = qwglCreateContext( win32.hDC ) ) == 0 ) { common->Printf( "^3failed^0\n" ); return false; } common->Printf( "succeeded\n" ); common->Printf( "...making context current: " ); if ( !qwglMakeCurrent( win32.hDC, win32.hGLRC ) ) { qwglDeleteContext( win32.hGLRC ); win32.hGLRC = NULL; common->Printf( "^3failed^0\n" ); return false; } common->Printf( "succeeded\n" ); return true; }
static qboolean VID_CreateWindow( int width, int height, qboolean fullscreen ) { RECT r; int stylebits; int x, y, w, h, exstyle; /* Register the frame class */ if (!s_classRegistered) { WNDCLASS wc; memset( &wc, 0, sizeof( wc ) ); wc.style = 0; wc.lpfnWndProc = (WNDPROC)glw_state.wndproc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = glw_state.hInstance; wc.hIcon = LoadIcon(glw_state.hInstance, MAKEINTRESOURCE(IDI_ICON1)); wc.hCursor = LoadCursor (NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH); wc.lpszMenuName = 0; wc.lpszClassName = WINDOW_CLASS_NAME; if (!RegisterClass(&wc)) { PrintWinError("VID_CreateWindow: RegisterClass", true); return false; } s_classRegistered = true; } if (fullscreen) { exstyle = WS_EX_TOPMOST; stylebits = WS_POPUP|WS_VISIBLE; w = width; h = height; x = 0; y = 0; } else { exstyle = 0; stylebits = WINDOW_STYLE; r.left = 0; r.top = 0; r.right = width; r.bottom = height; AdjustWindowRect (&r, stylebits, FALSE); w = r.right - r.left; h = r.bottom - r.top; x = vid_xpos->integer; y = vid_ypos->integer; } glw_state.hWnd = CreateWindowEx ( exstyle, WINDOW_CLASS_NAME, APPLICATION, stylebits, x, y, w, h, NULL, NULL, glw_state.hInstance, NULL); if (!glw_state.hWnd) { PrintWinError("VID_CreateWindow: CreateWindowEx", true); return false; } ShowWindow( glw_state.hWnd, SW_SHOW ); UpdateWindow( glw_state.hWnd ); // init all the gl stuff for the window if (!GLimp_InitGL()) { Com_Printf ( "VID_CreateWindow() - GLimp_InitGL failed\n"); if (glw_state.hGLRC) { qwglDeleteContext( glw_state.hGLRC ); glw_state.hGLRC = NULL; } if (glw_state.hDC) { ReleaseDC( glw_state.hWnd, glw_state.hDC ); glw_state.hDC = NULL; } ShowWindow( glw_state.hWnd, SW_HIDE ); DestroyWindow( glw_state.hWnd ); glw_state.hWnd = NULL; return false; } SetForegroundWindow( glw_state.hWnd ); SetFocus( glw_state.hWnd ); vid_scaled_width = (int)ceilf((float)width / gl_scale->value); vid_scaled_height = (int)ceilf((float)height / gl_scale->value); //round to powers of 8/2 to avoid blackbars width = (vid_scaled_width+7)&~7; height = (vid_scaled_height+1)&~1; // let the sound and input subsystems know about the new window VID_NewWindow( width, height ); //VID_NewWindow( width / gl_scale->value, height / gl_scale->value); return true; }
static int GLimp_InitGL( void ) { PIXELFORMATDESCRIPTOR pfd = { sizeof( PIXELFORMATDESCRIPTOR ), // size of this pfd 1, // version number PFD_DRAW_TO_WINDOW | // support window PFD_SUPPORT_OPENGL | // support OpenGL PFD_DOUBLEBUFFER, // double buffered PFD_TYPE_RGBA, // RGBA type 32, // 32-bit color depth 0, 0, 0, 0, 0, 0, // color bits ignored 0, // no alpha buffer 0, // shift bit ignored 0, // no accumulation buffer 0, 0, 0, 0, // accum bits ignored 24, // 32-bit z-buffer 0, // no stencil buffer 0, // no auxiliary buffer PFD_MAIN_PLANE, // main layer 0, // reserved 0, 0, 0 // layer masks ignored }; int pixelformat; if( r_stencilbits->integer == 8 || r_stencilbits->integer == 16 ) pfd.cStencilBits = r_stencilbits->integer; /* ** set PFD_STEREO if necessary */ if( glConfig.stereoEnabled ) { ri.Com_DPrintf( "...attempting to use stereo\n" ); pfd.dwFlags |= PFD_STEREO; } /* ** Get a DC for the specified window */ if( glw_state.hDC != NULL ) ri.Com_Printf( "GLimp_Init() - non-NULL DC exists\n" ); if( ( glw_state.hDC = GetDC( glw_state.hWnd ) ) == NULL ) { ri.Com_Printf( "GLimp_Init() - GetDC failed\n" ); return false; } if( ( pixelformat = ChoosePixelFormat( glw_state.hDC, &pfd ) ) == 0 ) { ri.Com_Printf( "GLimp_Init() - ChoosePixelFormat failed\n" ); return false; } if( SetPixelFormat( glw_state.hDC, pixelformat, &pfd ) == FALSE ) { ri.Com_Printf( "GLimp_Init() - SetPixelFormat failed\n" ); return false; } DescribePixelFormat( glw_state.hDC, pixelformat, sizeof( pfd ), &pfd ); glConfig.stencilBits = pfd.cStencilBits; /* ** report if stereo is desired but unavailable */ if( !( pfd.dwFlags & PFD_STEREO ) && glConfig.stereoEnabled ) { ri.Com_Printf( "...failed to select stereo pixel format\n" ); glConfig.stereoEnabled = false; } /* ** startup the OpenGL subsystem by creating a context and making ** it current */ if( ( glw_state.hGLRC = qwglCreateContext( glw_state.hDC ) ) == 0 ) { ri.Com_Printf( "GLimp_Init() - qwglCreateContext failed\n" ); goto fail; } if( !qwglMakeCurrent( glw_state.hDC, glw_state.hGLRC ) ) { ri.Com_Printf( "GLimp_Init() - qwglMakeCurrent failed\n" ); goto fail; } /* ** print out PFD specifics */ ri.Com_Printf( "GL PFD: color(%d-bits) Z(%d-bit) stencil(%d-bits)\n", ( int ) pfd.cColorBits, ( int ) pfd.cDepthBits, ( int )pfd.cStencilBits ); return true; fail: if( glw_state.hGLRC ) { qwglDeleteContext( glw_state.hGLRC ); glw_state.hGLRC = NULL; } if( glw_state.hDC ) { ReleaseDC( glw_state.hWnd, glw_state.hDC ); glw_state.hDC = NULL; } return false; }
/* ** GLimp_SharedContext_Destroy */ void GLimp_SharedContext_Destroy( void *ctx ) { if( qwglDeleteContext ) { qwglDeleteContext( ctx ); } }
void QEW_StopGL( HWND hWnd, HGLRC hGLRC, HDC hDC ) { qwglMakeCurrent( NULL, NULL ); qwglDeleteContext( hGLRC ); ReleaseDC( hWnd, hDC ); }
void GLimp_Shutdown( void ) { //Knightmare- added Vic's hardware gamma ramp if ( !r_ignorehwgamma->value ) { if( qwglSetDeviceGammaRamp3DFX ) { WORD newramp[3*256]; int j; for( j = 0; j < 256; j++ ) { newramp[j+0] = original_ramp[0][j]; newramp[j+256] = original_ramp[1][j]; newramp[j+512] = original_ramp[2][j]; } qwglSetDeviceGammaRamp3DFX ( glw_state.hDC, newramp ); } else { SetDeviceGammaRamp (glw_state.hDC, original_ramp); } } //end Knightmare if ( qwglMakeCurrent && !qwglMakeCurrent( NULL, NULL ) ) VID_Printf( PRINT_ALL, "ref_gl::R_Shutdown() - wglMakeCurrent failed\n"); if ( glw_state.hGLRC ) { if ( qwglDeleteContext && !qwglDeleteContext( glw_state.hGLRC ) ) VID_Printf( PRINT_ALL, "ref_gl::R_Shutdown() - wglDeleteContext failed\n"); glw_state.hGLRC = NULL; } if (glw_state.hDC) { if ( !ReleaseDC( glw_state.hWnd, glw_state.hDC ) ) VID_Printf( PRINT_ALL, "ref_gl::R_Shutdown() - ReleaseDC failed\n" ); glw_state.hDC = NULL; } if (glw_state.hWnd) { //Knightmare- remove leftover button on taskbar ShowWindow (glw_state.hWnd, SW_HIDE); //end Knightmare DestroyWindow ( glw_state.hWnd ); glw_state.hWnd = NULL; } if ( glw_state.log_fp ) { fclose( glw_state.log_fp ); glw_state.log_fp = 0; } UnregisterClass (WINDOW_CLASS_NAME, glw_state.hInstance); if ( gl_state.fullscreen ) { ChangeDisplaySettings( 0, 0 ); gl_state.fullscreen = false; } }
void GLimp_Shutdown() { // FIXME: Brian, we need better fallbacks from partially initialized failures if ( !qwglMakeCurrent ) { return; } ri.Printf( PRINT_DEVELOPER, "Shutting down OpenGL subsystem\n" ); GLW_RestoreGamma(); const char* success[] = { "failed", "success" }; int retVal; // set current context to NULL if ( qwglMakeCurrent ) { retVal = qwglMakeCurrent( NULL, NULL ) != 0; ri.Printf( PRINT_DEVELOPER, "...wglMakeCurrent( NULL, NULL ): %s\n", success[retVal] ); } // delete HGLRC if ( glw_state.hGLRC ) { retVal = qwglDeleteContext( glw_state.hGLRC ) != 0; ri.Printf( PRINT_DEVELOPER, "...deleting GL context: %s\n", success[retVal] ); glw_state.hGLRC = NULL; } // release DC if ( glw_state.hDC ) { retVal = ReleaseDC( g_wv.hWnd, glw_state.hDC ) != 0; ri.Printf( PRINT_DEVELOPER, "...releasing DC: %s\n", success[retVal] ); glw_state.hDC = NULL; } // destroy window if ( g_wv.hWnd ) { ri.Printf( PRINT_DEVELOPER, "...destroying window\n" ); ShowWindow( g_wv.hWnd, SW_HIDE ); DestroyWindow( g_wv.hWnd ); g_wv.hWnd = NULL; glw_state.pixelFormatSet = qfalse; } // reset display settings if ( glw_state.cdsFullscreen ) { ri.Printf( PRINT_DEVELOPER, "...resetting display\n" ); ChangeDisplaySettings( 0, 0 ); glw_state.cdsFullscreen = qfalse; } // shutdown QGL subsystem QGL_Shutdown(); memset( &glConfig, 0, sizeof( glConfig ) ); memset( &glState, 0, sizeof( glState ) ); }
qboolean GLimp_InitGL (void) { PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd 1, // version number PFD_DRAW_TO_WINDOW | // support window PFD_SUPPORT_OPENGL | // support OpenGL PFD_DOUBLEBUFFER, // double buffered PFD_TYPE_RGBA, // RGBA type 32, // 32-bit color depth // was 24 0, 0, 0, 0, 0, 0, // color bits ignored 0, // no alpha buffer 0, // shift bit ignored 0, // no accumulation buffer 0, 0, 0, 0, // accum bits ignored //Knightmare 12/24/2001- stencil buffer 24, // 24-bit z-buffer, was 32 8, // 8-bit stencil buffer //end Knightmare 0, // no auxiliary buffer PFD_MAIN_PLANE, // main layer 0, // reserved 0, 0, 0 // layer masks ignored }; int pixelformat; cvar_t *stereo; stereo = Cvar_Get( "cl_stereo", "0", 0 ); /* ** set PFD_STEREO if necessary */ if ( stereo->value != 0 ) { VID_Printf( PRINT_ALL, "...attempting to use stereo\n" ); pfd.dwFlags |= PFD_STEREO; gl_state.stereo_enabled = true; } else { gl_state.stereo_enabled = false; } /* ** figure out if we're running on a minidriver or not */ if ( strstr( gl_driver->string, "opengl32" ) != 0 ) glw_state.minidriver = false; else glw_state.minidriver = true; /* ** Get a DC for the specified window */ if ( glw_state.hDC != NULL ) VID_Printf( PRINT_ALL, "GLimp_Init() - non-NULL DC exists\n" ); if ( ( glw_state.hDC = GetDC( glw_state.hWnd ) ) == NULL ) { VID_Printf( PRINT_ALL, "GLimp_Init() - GetDC failed\n" ); return false; } if ( glw_state.minidriver ) { if ( (pixelformat = qwglChoosePixelFormat( glw_state.hDC, &pfd)) == 0 ) { VID_Printf (PRINT_ALL, "GLimp_Init() - qwglChoosePixelFormat failed\n"); return false; } if ( qwglSetPixelFormat( glw_state.hDC, pixelformat, &pfd) == FALSE ) { VID_Printf (PRINT_ALL, "GLimp_Init() - qwglSetPixelFormat failed\n"); return false; } qwglDescribePixelFormat( glw_state.hDC, pixelformat, sizeof( pfd ), &pfd ); } else { if ( ( pixelformat = ChoosePixelFormat( glw_state.hDC, &pfd)) == 0 ) { VID_Printf (PRINT_ALL, "GLimp_Init() - ChoosePixelFormat failed\n"); return false; } if ( SetPixelFormat( glw_state.hDC, pixelformat, &pfd) == FALSE ) { VID_Printf (PRINT_ALL, "GLimp_Init() - SetPixelFormat failed\n"); return false; } DescribePixelFormat( glw_state.hDC, pixelformat, sizeof( pfd ), &pfd ); if ( !( pfd.dwFlags & PFD_GENERIC_ACCELERATED ) ) { extern cvar_t *gl_allow_software; if ( gl_allow_software->value ) glw_state.mcd_accelerated = true; else glw_state.mcd_accelerated = false; } else { glw_state.mcd_accelerated = true; } } /* ** report if stereo is desired but unavailable */ if ( !( pfd.dwFlags & PFD_STEREO ) && ( stereo->value != 0 ) ) { VID_Printf( PRINT_ALL, "...failed to select stereo pixel format\n" ); Cvar_SetValue( "cl_stereo", 0 ); gl_state.stereo_enabled = false; } /* ** startup the OpenGL subsystem by creating a context and making ** it current */ if ( ( glw_state.hGLRC = qwglCreateContext( glw_state.hDC ) ) == 0 ) { VID_Printf (PRINT_ALL, "GLimp_Init() - qwglCreateContext failed\n"); goto fail; } if ( !qwglMakeCurrent( glw_state.hDC, glw_state.hGLRC ) ) { VID_Printf (PRINT_ALL, "GLimp_Init() - qwglMakeCurrent failed\n"); goto fail; } if ( !VerifyDriver() ) { VID_Printf( PRINT_ALL, "GLimp_Init() - no hardware acceleration detected.\nPlease install drivers provided by your video card/GPU vendor.\n" ); goto fail; } /* ** print out PFD specifics */ VID_Printf( PRINT_ALL, "PIXELFORMAT: color(%d-bits) Z(%d-bit)\n", ( int ) pfd.cColorBits, ( int ) pfd.cDepthBits ); //Knightmare- Vic's hardware gamma stuff if ( !r_ignorehwgamma->value ) { if( qwglGetDeviceGammaRamp3DFX ) { WORD newramp[3*256]; int j; gl_state.gammaRamp = qwglGetDeviceGammaRamp3DFX ( glw_state.hDC, newramp ); for( j = 0; j < 256; j++ ) { original_ramp[0][j] = newramp[j+0]; original_ramp[1][j] = newramp[j+256]; original_ramp[2][j] = newramp[j+512]; } } else { gl_state.gammaRamp = GetDeviceGammaRamp ( glw_state.hDC, original_ramp ); } } else { gl_state.gammaRamp = false; } if (gl_state.gammaRamp) vid_gamma->modified = true; // moved these to GL_SetDefaultState //gl_state.blend = false; //gl_state.alphaTest = false; //end Knightmare //Knightmare- 12/24/2001- stecil buffer { char buffer[1024]; strcpy( buffer, qglGetString( GL_RENDERER ) ); strlwr( buffer ); if (strstr(buffer, "Voodoo3")) { VID_Printf( PRINT_ALL, "... Voodoo3 has no stencil buffer\n" ); gl_config.have_stencil = false; } else { if (pfd.cStencilBits) { VID_Printf( PRINT_ALL, "... Using stencil buffer\n" ); gl_config.have_stencil = true; // Stencil shadows - MrG } } } //if (pfd.cStencilBits) // gl_config.have_stencil = true; //end Knightmare /* Moved to GL_SetDefaultState in r_glstate.c // Vertex arrays qglEnableClientState (GL_TEXTURE_COORD_ARRAY); qglEnableClientState (GL_VERTEX_ARRAY); qglEnableClientState (GL_COLOR_ARRAY); qglTexCoordPointer (2, GL_FLOAT, sizeof(texCoordArray[0][0]), texCoordArray[0][0]); qglVertexPointer (3, GL_FLOAT, sizeof(vertexArray[0]), vertexArray[0]); qglColorPointer (4, GL_FLOAT, sizeof(colorArray[0]), colorArray[0]); //gl_state.activetmu[0] = true; // end vertex arrays */ return true; fail: if ( glw_state.hGLRC ) { qwglDeleteContext( glw_state.hGLRC ); glw_state.hGLRC = NULL; } if ( glw_state.hDC ) { ReleaseDC( glw_state.hWnd, glw_state.hDC ); glw_state.hDC = NULL; } return false; }
/* ==================== GLW_InitDriver Set the pixelformat for the window before it is shown, and create the rendering context ==================== */ static bool GLW_InitDriver( glimpParms_t parms ) { PIXELFORMATDESCRIPTOR src = { sizeof( PIXELFORMATDESCRIPTOR ), // size of this pfd 1, // version number PFD_DRAW_TO_WINDOW | // support window PFD_SUPPORT_OPENGL | // support OpenGL PFD_DOUBLEBUFFER, // double buffered PFD_TYPE_RGBA, // RGBA type 32, // 32-bit color depth 0, 0, 0, 0, 0, 0, // color bits ignored 8, // 8 bit destination alpha 0, // shift bit ignored 0, // no accumulation buffer 0, 0, 0, 0, // accum bits ignored 24, // 24-bit z-buffer 8, // 8-bit stencil buffer 0, // no auxiliary buffer PFD_MAIN_PLANE, // main layer 0, // reserved 0, 0, 0 // layer masks ignored }; common->Printf( "Initializing OpenGL driver\n" ); // // get a DC for our window if we don't already have one allocated // if( win32.hDC == NULL ) { common->Printf( "...getting DC: " ); if( ( win32.hDC = GetDC( win32.hWnd ) ) == NULL ) { common->Printf( "^3failed^0\n" ); return false; } common->Printf( "succeeded\n" ); } // the multisample path uses the wgl if( wglChoosePixelFormatARB ) { win32.pixelformat = GLW_ChoosePixelFormat( win32.hDC, parms.multiSamples, parms.stereo ); } else { // this is the "classic" choose pixel format path common->Printf( "Using classic ChoosePixelFormat\n" ); // eventually we may need to have more fallbacks, but for // now, ask for everything if( parms.stereo ) { common->Printf( "...attempting to use stereo\n" ); src.dwFlags |= PFD_STEREO; } // // choose, set, and describe our desired pixel format. If we're // using a minidriver then we need to bypass the GDI functions, // otherwise use the GDI functions. // if( ( win32.pixelformat = ChoosePixelFormat( win32.hDC, &src ) ) == 0 ) { common->Printf( "...^3GLW_ChoosePFD failed^0\n" ); return false; } common->Printf( "...PIXELFORMAT %d selected\n", win32.pixelformat ); } // get the full info DescribePixelFormat( win32.hDC, win32.pixelformat, sizeof( win32.pfd ), &win32.pfd ); glConfig.colorBits = win32.pfd.cColorBits; glConfig.depthBits = win32.pfd.cDepthBits; glConfig.stencilBits = win32.pfd.cStencilBits; // XP seems to set this incorrectly if( !glConfig.stencilBits ) { glConfig.stencilBits = 8; } // the same SetPixelFormat is used either way if( SetPixelFormat( win32.hDC, win32.pixelformat, &win32.pfd ) == FALSE ) { common->Printf( "...^3SetPixelFormat failed^0\n", win32.hDC ); return false; } // // startup the OpenGL subsystem by creating a context and making it current // common->Printf( "...creating GL context: " ); win32.hGLRC = CreateOpenGLContextOnDC( win32.hDC, r_debugContext.GetBool() ); if( win32.hGLRC == 0 ) { common->Printf( "^3failed^0\n" ); return false; } common->Printf( "succeeded\n" ); common->Printf( "...making context current: " ); if( !qwglMakeCurrent( win32.hDC, win32.hGLRC ) ) { qwglDeleteContext( win32.hGLRC ); win32.hGLRC = NULL; common->Printf( "^3failed^0\n" ); return false; } common->Printf( "succeeded\n" ); return true; }
static int SetupGL(int colorbits, int depthbits, int stencilbits, int multisamples) { PIXELFORMATDESCRIPTOR pfd; int pixelformat; // create the main window Win_Init(); if (colorbits == 0) colorbits = 24; if (depthbits == 0) depthbits = colorbits > 16 ? 24 : 16; if (depthbits < 24) stencilbits = 0; // choose pixel format if (qwglChoosePixelFormatARB && multisamples > 1) { int iAttributes[20]; UINT numFormats; iAttributes[0] = WGL_DRAW_TO_WINDOW_ARB; iAttributes[1] = TRUE; iAttributes[2] = WGL_SUPPORT_OPENGL_ARB; iAttributes[3] = TRUE; iAttributes[4] = WGL_DOUBLE_BUFFER_ARB; iAttributes[5] = TRUE; iAttributes[6] = WGL_PIXEL_TYPE_ARB; iAttributes[7] = WGL_TYPE_RGBA_ARB; iAttributes[8] = WGL_COLOR_BITS_ARB; iAttributes[9] = colorbits; iAttributes[10] = WGL_DEPTH_BITS_ARB; iAttributes[11] = depthbits; iAttributes[12] = WGL_STENCIL_BITS_ARB; iAttributes[13] = stencilbits; iAttributes[14] = WGL_SAMPLE_BUFFERS_ARB; iAttributes[15] = 1; iAttributes[16] = WGL_SAMPLES_ARB; iAttributes[17] = multisamples; iAttributes[18] = 0; iAttributes[19] = 0; if (qwglChoosePixelFormatARB(win.dc, iAttributes, NULL, 1, &pixelformat, &numFormats) == FALSE) { ReportLastError("wglChoosePixelFormatARB"); goto soft; } if (numFormats == 0) { Com_EPrintf("No suitable OpenGL pixelformat found for %d multisamples\n", multisamples); goto soft; } } else { memset(&pfd, 0, sizeof(pfd)); pfd.nSize = sizeof(pfd); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = colorbits; pfd.cDepthBits = depthbits; pfd.cStencilBits = stencilbits; pfd.iLayerType = PFD_MAIN_PLANE; if (glw.minidriver) { if ((pixelformat = qwglChoosePixelFormat(win.dc, &pfd)) == 0) { ReportLastError("wglChoosePixelFormat"); goto soft; } } else { if ((pixelformat = ChoosePixelFormat(win.dc, &pfd)) == 0) { ReportLastError("ChoosePixelFormat"); goto soft; } } } // set pixel format if (glw.minidriver) { qwglDescribePixelFormat(win.dc, pixelformat, sizeof(pfd), &pfd); ReportPixelFormat(pixelformat, &pfd); if (qwglSetPixelFormat(win.dc, pixelformat, &pfd) == FALSE) { ReportLastError("wglSetPixelFormat"); goto soft; } } else { DescribePixelFormat(win.dc, pixelformat, sizeof(pfd), &pfd); ReportPixelFormat(pixelformat, &pfd); if (SetPixelFormat(win.dc, pixelformat, &pfd) == FALSE) { ReportLastError("SetPixelFormat"); goto soft; } } // check for software emulation if (pfd.dwFlags & PFD_GENERIC_FORMAT) { if (!gl_allow_software->integer) { Com_EPrintf("No hardware OpenGL acceleration detected\n"); goto soft; } Com_WPrintf("...using software emulation\n"); } else if (pfd.dwFlags & PFD_GENERIC_ACCELERATED) { Com_DPrintf("...MCD acceleration found\n"); win.flags |= QVF_ACCELERATED; } else { Com_DPrintf("...ICD acceleration found\n"); win.flags |= QVF_ACCELERATED; } // startup the OpenGL subsystem by creating a context and making it current if ((glw.hGLRC = qwglCreateContext(win.dc)) == NULL) { ReportLastError("wglCreateContext"); goto hard; } if (qwglMakeCurrent(win.dc, glw.hGLRC) == FALSE) { ReportLastError("wglMakeCurrent"); qwglDeleteContext(glw.hGLRC); glw.hGLRC = NULL; goto hard; } return FAIL_OK; soft: // it failed, clean up Win_Shutdown(); return FAIL_SOFT; hard: Win_Shutdown(); return FAIL_HARD; }
static int GLimp_InitGL( void ) { PIXELFORMATDESCRIPTOR pfd = { sizeof( PIXELFORMATDESCRIPTOR ), // size of this pfd 1, // version number PFD_DRAW_TO_WINDOW | // support window PFD_SUPPORT_OPENGL | // support OpenGL PFD_DOUBLEBUFFER, // double buffered PFD_TYPE_RGBA, // RGBA type 32, // 32-bit color depth 0, 0, 0, 0, 0, 0, // color bits ignored 0, // no alpha buffer 0, // shift bit ignored 0, // no accumulation buffer 0, 0, 0, 0, // accum bits ignored 24, // 32-bit z-buffer 0, // no stencil buffer 0, // no auxiliary buffer PFD_MAIN_PLANE, // main layer 0, // reserved 0, 0, 0 // layer masks ignored }; int pixelformat; cvar_t *stereo; stereo = Cvar_Get( "cl_stereo", "0", 0 ); pfd.cStencilBits = max( 0, r_stencilbits->integer ); if( pfd.cStencilBits != 0 ) glState.stencilEnabled = qtrue; else glState.stencilEnabled = qfalse; /* ** set PFD_STEREO if necessary */ if( stereo->integer != 0 ) { Com_Printf( "...attempting to use stereo\n" ); pfd.dwFlags |= PFD_STEREO; glState.stereoEnabled = qtrue; } else { glState.stereoEnabled = qfalse; } /* ** figure out if we're running on a minidriver or not */ if( strstr( gl_driver->string, "opengl32" ) != 0 ) glw_state.minidriver = qfalse; else glw_state.minidriver = qtrue; /* ** Get a DC for the specified window */ if( glw_state.hDC != NULL ) Com_Printf( "GLimp_Init() - non-NULL DC exists\n" ); if( ( glw_state.hDC = GetDC( glw_state.hWnd ) ) == NULL ) { Com_Printf( "GLimp_Init() - GetDC failed\n" ); return qfalse; } if( glw_state.minidriver ) { if( ( pixelformat = qwglChoosePixelFormat( glw_state.hDC, &pfd ) ) == 0 ) { Com_Printf( "GLimp_Init() - qwglChoosePixelFormat failed\n" ); return qfalse; } if( qwglSetPixelFormat( glw_state.hDC, pixelformat, &pfd ) == FALSE ) { Com_Printf( "GLimp_Init() - qwglSetPixelFormat failed\n" ); return qfalse; } qwglDescribePixelFormat( glw_state.hDC, pixelformat, sizeof( pfd ), &pfd ); } else { if( ( pixelformat = ChoosePixelFormat( glw_state.hDC, &pfd ) ) == 0 ) { Com_Printf( "GLimp_Init() - ChoosePixelFormat failed\n" ); return qfalse; } if( SetPixelFormat( glw_state.hDC, pixelformat, &pfd ) == FALSE ) { Com_Printf( "GLimp_Init() - SetPixelFormat failed\n" ); return qfalse; } DescribePixelFormat( glw_state.hDC, pixelformat, sizeof( pfd ), &pfd ); if( !( pfd.dwFlags & PFD_GENERIC_ACCELERATED ) ) { extern cvar_t *r_allow_software; if( r_allow_software->integer ) glw_state.mcd_accelerated = qtrue; else glw_state.mcd_accelerated = qfalse; } else { glw_state.mcd_accelerated = qtrue; } } /* ** report if stereo is desired but unavailable */ if( !( pfd.dwFlags & PFD_STEREO ) && ( stereo->integer != 0 ) ) { Com_Printf( "...failed to select stereo pixel format\n" ); Cvar_SetValue( "cl_stereo", 0 ); glState.stereoEnabled = qfalse; } /* ** startup the OpenGL subsystem by creating a context and making ** it current */ if( ( glw_state.hGLRC = qwglCreateContext( glw_state.hDC ) ) == 0 ) { Com_Printf( "GLimp_Init() - qwglCreateContext failed\n" ); goto fail; } if( !qwglMakeCurrent( glw_state.hDC, glw_state.hGLRC ) ) { Com_Printf( "GLimp_Init() - qwglMakeCurrent failed\n" ); goto fail; } if( !VerifyDriver() ) { Com_Printf( "GLimp_Init() - no hardware acceleration detected\n" ); goto fail; } /* ** print out PFD specifics */ Com_Printf( "GL PFD: color(%d-bits) Z(%d-bit) stencil(%d-bits)\n", ( int ) pfd.cColorBits, ( int ) pfd.cDepthBits, ( int )pfd.cStencilBits ); return qtrue; fail: if( glw_state.hGLRC ) { qwglDeleteContext( glw_state.hGLRC ); glw_state.hGLRC = NULL; } if( glw_state.hDC ) { ReleaseDC( glw_state.hWnd, glw_state.hDC ); glw_state.hDC = NULL; } return qfalse; }
/* ** GLimp_Shutdown ** ** This routine does all OS specific shutdown procedures for the OpenGL ** subsystem. */ void GLimp_Shutdown( void ) { // const char *strings[] = { "soft", "hard" }; const char *success[] = { "failed", "success" }; int retVal; // FIXME: Brian, we need better fallbacks from partially initialized failures if ( !qwglMakeCurrent ) { return; } ri.Printf( PRINT_ALL, "Shutting down OpenGL subsystem\n" ); // restore gamma. We do this first because 3Dfx's extension needs a valid OGL subsystem WG_RestoreGamma(); // delete display lists GLW_DeleteDefaultLists(); // set current context to NULL if ( qwglMakeCurrent ) { retVal = qwglMakeCurrent( NULL, NULL ) != 0; ri.Printf( PRINT_ALL, "...wglMakeCurrent( NULL, NULL ): %s\n", success[retVal] ); } // delete HGLRC if ( glw_state.hGLRC ) { retVal = qwglDeleteContext( glw_state.hGLRC ) != 0; ri.Printf( PRINT_ALL, "...deleting GL context: %s\n", success[retVal] ); glw_state.hGLRC = NULL; } // release DC if ( glw_state.hDC ) { retVal = ReleaseDC( g_wv.hWnd, glw_state.hDC ) != 0; ri.Printf( PRINT_ALL, "...releasing DC: %s\n", success[retVal] ); glw_state.hDC = NULL; } // destroy window if ( g_wv.hWnd ) { ri.Printf( PRINT_ALL, "...destroying window\n" ); ShowWindow( g_wv.hWnd, SW_HIDE ); DestroyWindow( g_wv.hWnd ); g_wv.hWnd = NULL; glw_state.pixelFormatSet = qfalse; } // close the r_logFile if ( glw_state.log_fp ) { fclose( glw_state.log_fp ); glw_state.log_fp = 0; } // reset display settings if ( glw_state.cdsFullscreen ) { ri.Printf( PRINT_ALL, "...resetting display\n" ); ChangeDisplaySettings( 0, 0 ); glw_state.cdsFullscreen = qfalse; } // shutdown QGL subsystem QGL_Shutdown(); memset( &glConfig, 0, sizeof( glConfig ) ); memset( &glState, 0, sizeof( glState ) ); }