/* ** GLimp_SetMode */ rserr_t GLimp_SetMode( int x, int y, int width, int height, int displayFrequency, qboolean fullscreen, qboolean wideScreen ) { const char *win_fs[] = { "W", "FS" }; // check whether we can toggle fullscreen without a vid_restart if( glw_state.hWnd ) { if( glConfig.width == width && glConfig.height == height && fullscreen != glConfig.fullScreen ) { glConfig.fullScreen = VID_SetFullscreenMode( displayFrequency, fullscreen ); if( glConfig.fullScreen == fullscreen ) { VID_SetWindowSize( fullscreen ); return rserr_ok; } return rserr_restart_required; } } ri.Com_Printf( "Initializing OpenGL display\n" ); ri.Com_Printf( "...setting mode:" ); // disable fullscreen if rendering to a parent window if( glw_state.parenthWnd ) { RECT parentWindowRect; fullscreen = qfalse; wideScreen = qfalse; GetWindowRect( glw_state.parenthWnd, &parentWindowRect ); width = parentWindowRect.right - parentWindowRect.left; height = parentWindowRect.bottom - parentWindowRect.top; } ri.Com_Printf( " %d %d %s\n", width, height, win_fs[fullscreen] ); // destroy the existing window if( glw_state.hWnd ) { GLimp_Shutdown(); } glw_state.win_x = x; glw_state.win_y = y; glConfig.width = width; glConfig.height = height; glConfig.wideScreen = wideScreen; glConfig.fullScreen = VID_SetFullscreenMode( displayFrequency, fullscreen ); if( !VID_CreateWindow() ) { return rserr_invalid_mode; } return ( fullscreen == glConfig.fullScreen ? rserr_ok : rserr_invalid_fullscreen ); }
/* ** VID_SetFullscreenMode */ static bool VID_SetFullscreenMode( int displayFrequency, bool fullscreen ) { // do a CDS if needed if( fullscreen ) { int a; DEVMODE dm; ri.Com_Printf( "...attempting fullscreen\n" ); memset( &dm, 0, sizeof( dm ) ); dm.dmSize = sizeof( dm ); dm.dmPelsWidth = glConfig.width; dm.dmPelsHeight = glConfig.height; dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT; if( displayFrequency > 0 ) { dm.dmFields |= DM_DISPLAYFREQUENCY; dm.dmDisplayFrequency = displayFrequency; ri.Com_Printf( "...using display frequency %i\n", dm.dmDisplayFrequency ); } ri.Com_Printf( "...calling CDS: " ); a = ChangeDisplaySettings( &dm, CDS_FULLSCREEN ); if( a == DISP_CHANGE_SUCCESSFUL ) { ri.Com_Printf( "ok\n" ); VID_SetWindowSize( true ); return true; } ri.Com_Printf( "failed: %x\n", a ); } ChangeDisplaySettings( 0, 0 ); VID_SetWindowSize( false ); return false; }
static bool VID_CreateWindow( void ) { bool fullscreen = glConfig.fullScreen; HWND parentHWND = glw_state.parenthWnd; #ifdef WITH_UTF8 WNDCLASSW wc; #else WNDCLASS wc; #endif Q_snprintfz( glw_state.windowClassName, sizeof( glw_state.windowClassName ), "%sWndClass", glw_state.applicationName ); #ifdef WITH_UTF8 MultiByteToWideChar( CP_UTF8, 0, glw_state.windowClassName, -1, glw_state.windowClassNameW, sizeof( glw_state.windowClassNameW ) ); glw_state.windowClassNameW[sizeof( glw_state.windowClassNameW )/sizeof( glw_state.windowClassNameW[0] ) - 1] = 0; #endif /* Register the frame class */ 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( glw_state.applicationIconResourceID ) ); wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH ); wc.lpszMenuName = 0; #ifdef WITH_UTF8 wc.lpszClassName = (LPCWSTR)glw_state.windowClassNameW; if( !RegisterClassW( &wc ) ) #else wc.lpszClassName = (LPCSTR)glw_state.windowClassName; if( !RegisterClass( &wc ) ) #endif Sys_Error( "Couldn't register window class" ); glw_state.hWnd = #ifdef WITH_UTF8 CreateWindowExW( #else CreateWindowEx( #endif 0, #ifdef WITH_UTF8 glw_state.windowClassNameW, glw_state.applicationNameW, #else glw_state.windowClassName, glw_state.applicationName, #endif 0, 0, 0, 0, 0, parentHWND, NULL, glw_state.hInstance, NULL ); if( !glw_state.hWnd ) Sys_Error( "Couldn't create window" ); VID_SetWindowSize( fullscreen ); // init all the gl stuff for the window if( !GLimp_InitGL() ) { ri.Com_Printf( "VID_CreateWindow() - GLimp_InitGL failed\n" ); return false; } return true; }
/* ** VID_SetFullscreenMode */ qboolean VID_SetFullscreenMode( qboolean fullscreen ) { // do a CDS if needed if( fullscreen ) { int a; DEVMODE dm; Com_DPrintf( "...attempting fullscreen\n" ); memset( &dm, 0, sizeof( dm ) ); dm.dmSize = sizeof( dm ); dm.dmPelsWidth = glState.width; dm.dmPelsHeight = glState.height; dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT; if( r_colorbits->integer != 0 ) { dm.dmBitsPerPel = r_colorbits->integer; dm.dmFields |= DM_BITSPERPEL; Com_DPrintf( "...using r_bitdepth of %d\n", dm.dmBitsPerPel ); } else { HDC hdc = GetDC( NULL ); int bitspixel = GetDeviceCaps( hdc, BITSPIXEL ); Com_DPrintf( "...using desktop display depth of %d\n", bitspixel ); ReleaseDC( 0, hdc ); } if( vid_displayfrequency->integer > 0 ) { dm.dmFields |= DM_DISPLAYFREQUENCY; dm.dmDisplayFrequency = vid_displayfrequency->integer; Com_DPrintf( "...using display frequency %i\n", dm.dmDisplayFrequency ); } Com_DPrintf( "...calling CDS: " ); a = ChangeDisplaySettings( &dm, CDS_FULLSCREEN ); if( a == DISP_CHANGE_SUCCESSFUL ) { Com_DPrintf( "ok\n" ); if( glw_state.hWnd ) { VID_SetWindowSize( qtrue ); } return qtrue; } else { Com_DPrintf( "failed: %i\n", a ); Com_DPrintf( "...calling CDS assuming dual monitors:" ); dm.dmPelsWidth = glState.width * 2; dm.dmPelsHeight = glState.height; dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT; if( r_colorbits->integer != 0 ) { dm.dmBitsPerPel = r_colorbits->integer; dm.dmFields |= DM_BITSPERPEL; Com_DPrintf( "...using r_bitdepth of %d\n", dm.dmBitsPerPel ); } if( vid_displayfrequency->integer > 0 ) { dm.dmFields |= DM_DISPLAYFREQUENCY; dm.dmDisplayFrequency = vid_displayfrequency->integer; Com_DPrintf( "...using display frequency %i\n", dm.dmDisplayFrequency ); } /* ** our first CDS failed, so maybe we're running on some weird dual monitor ** system */ if( ChangeDisplaySettings( &dm, CDS_FULLSCREEN ) != DISP_CHANGE_SUCCESSFUL ) { Com_DPrintf( " failed\n" ); Com_DPrintf( "...setting windowed mode\n" ); ChangeDisplaySettings( 0, 0 ); if( glw_state.hWnd ) { VID_SetWindowSize( qfalse ); } return qfalse; } else { Com_DPrintf( " ok\n" ); if( glw_state.hWnd ) { VID_SetWindowSize( qtrue ); } return qtrue; } } } else { Com_DPrintf( "...setting windowed mode\n" ); ChangeDisplaySettings( 0, 0 ); if( glw_state.hWnd ) { VID_SetWindowSize( qfalse ); } } return qfalse; }
static qboolean VID_CreateWindow( void ) { #define WITH_UTF8 // FIXME: turn non-Unicode code into a runtime fallback for Win9x #ifndef WITH_UTF8 WNDCLASS wc; #else WNDCLASSW wc; qboolean fullscreen = glState.fullScreen; HWND parentHWND = glw_state.parenthWnd; /* determine buffer size required for the unicode string */ WCHAR windowClassName[sizeof(WINDOW_CLASS_NAME)] = L""; MultiByteToWideChar( CP_ACP, 0, WINDOW_CLASS_NAME, -1, windowClassName, sizeof( windowClassName )-1 ); #endif /* Register the frame class */ 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_APPICON_VALUE ) ); wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hbrBackground = (HBRUSH)GetStockObject( GRAY_BRUSH ); wc.lpszMenuName = 0; #ifdef WITH_UTF8 wc.lpszClassName = (LPCWSTR)windowClassName; if( !RegisterClassW( &wc ) ) #else wc.lpszClassName = (LPCSTR)WINDOW_CLASS_NAME; if( !RegisterClass( &wc ) ) #endif Com_Error( ERR_FATAL, "Couldn't register window class" ); glw_state.hWnd = CreateWindowEx( 0, WINDOW_CLASS_NAME, APPLICATION, 0, 0, 0, 0, 0, parentHWND, NULL, glw_state.hInstance, NULL ); if( !glw_state.hWnd ) Com_Error( ERR_FATAL, "Couldn't create window" ); VID_SetWindowSize( fullscreen ); // init all the gl stuff for the window if( !GLimp_InitGL() ) { Com_Printf( "VID_CreateWindow() - GLimp_InitGL failed\n" ); return qfalse; } if( glw_state.parenthWnd ) PostMessage( glw_state.parenthWnd, UWM_APPACTIVE, WA_ACTIVE, 0 ); return qtrue; }
/* ** VID_SetFullscreenMode */ static bool VID_SetFullscreenMode( int displayFrequency, bool fullscreen ) { // do a CDS if needed if( fullscreen ) { int a; DEVMODE dm; HDC hdc; int bitspixel; ri.Com_DPrintf( "...attempting fullscreen\n" ); memset( &dm, 0, sizeof( dm ) ); dm.dmSize = sizeof( dm ); dm.dmPelsWidth = glConfig.width; dm.dmPelsHeight = glConfig.height; dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT; hdc = GetDC( NULL ); bitspixel = GetDeviceCaps( hdc, BITSPIXEL ); ri.Com_DPrintf( "...using desktop display depth of %d\n", bitspixel ); ReleaseDC( 0, hdc ); if( displayFrequency > 0 ) { dm.dmFields |= DM_DISPLAYFREQUENCY; dm.dmDisplayFrequency = displayFrequency; ri.Com_DPrintf( "...using display frequency %i\n", dm.dmDisplayFrequency ); } ri.Com_DPrintf( "...calling CDS: " ); a = ChangeDisplaySettings( &dm, CDS_FULLSCREEN ); if( a == DISP_CHANGE_SUCCESSFUL ) { ri.Com_DPrintf( "ok\n" ); if( glw_state.hWnd ) { VID_SetWindowSize( true ); } return true; } else { ri.Com_DPrintf( "failed: %i\n", a ); ri.Com_DPrintf( "...calling CDS assuming dual monitors:" ); dm.dmPelsWidth = glConfig.width * 2; dm.dmPelsHeight = glConfig.height; dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT; if( displayFrequency > 0 ) { dm.dmFields |= DM_DISPLAYFREQUENCY; dm.dmDisplayFrequency = displayFrequency; ri.Com_DPrintf( "...using display frequency %i\n", dm.dmDisplayFrequency ); } /* ** our first CDS failed, so maybe we're running on some weird dual monitor ** system */ if( ChangeDisplaySettings( &dm, CDS_FULLSCREEN ) != DISP_CHANGE_SUCCESSFUL ) { ri.Com_DPrintf( " failed\n" ); ri.Com_DPrintf( "...setting windowed mode\n" ); ChangeDisplaySettings( 0, 0 ); if( glw_state.hWnd ) { VID_SetWindowSize( false ); } return false; } else { ri.Com_DPrintf( " ok\n" ); if( glw_state.hWnd ) { VID_SetWindowSize( true ); } return true; } } } else { ri.Com_DPrintf( "...setting windowed mode\n" ); ChangeDisplaySettings( 0, 0 ); if( glw_state.hWnd ) { VID_SetWindowSize( false ); } } return false; }