Try to enforce selected fullscreen resolution

SDL has a bug (at least on Windows) where SDL_CreateWindow() with
SDL_WINDOW_FULLSCREEN doesn't use the configured resolution (if it's
higher than the current desktop resolution).
Try to work around that - based on Yamagi Quake II code.

Also, if GLimp_Init() fails, the "safe mode" fallback is now in
windowed mode instead of fullscreen mode.
This commit is contained in:
Daniel Gibson 2020-11-28 17:51:10 +01:00
parent 8c699cd030
commit d1b0073582
3 changed files with 68 additions and 1 deletions

View file

@ -673,7 +673,7 @@ void R_InitOpenGL( void ) {
// if we failed, set everything back to "safe mode"
// and try again
r_mode.SetInteger( 3 );
r_fullscreen.SetInteger( 1 );
r_fullscreen.SetInteger( 0 );
r_displayRefresh.SetInteger( 0 );
r_multiSamples.SetInteger( 0 );
}

View file

@ -211,6 +211,70 @@ bool GLimp_Init(glimpParms_t parms) {
continue;
}
/* Check if we're really in the requested display mode. There is
(or was) an SDL bug were SDL switched into the wrong mode
without giving an error code. See the bug report for details:
https://bugzilla.libsdl.org/show_bug.cgi?id=4700 */
if ((flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP)) == SDL_WINDOW_FULLSCREEN)
{
SDL_DisplayMode real_mode;
if (SDL_GetWindowDisplayMode(window, &real_mode) != 0)
{
SDL_DestroyWindow(window);
window = NULL;
common->Warning("Can't get display mode: %s\n", SDL_GetError());
return false; // trying other color depth etc is unlikely to help with this issue
}
if ((real_mode.w != parms.width) || (real_mode.h != parms.height))
{
common->Warning("Current display mode isn't requested display mode\n");
common->Warning("Likely SDL bug #4700, trying to work around it\n");
/* Mkay, try to hack around that. */
SDL_DisplayMode wanted_mode = {};
wanted_mode.w = parms.width;
wanted_mode.h = parms.height;
if (SDL_SetWindowDisplayMode(window, &wanted_mode) != 0)
{
SDL_DestroyWindow(window);
window = NULL;
common->Warning("Can't force resolution to %ix%i: %s\n", parms.width, parms.height, SDL_GetError());
return false; // trying other color depth etc is unlikely to help with this issue
}
/* The SDL doku says, that SDL_SetWindowSize() shouldn't be
used on fullscreen windows. But at least in my test with
SDL 2.0.9 the subsequent SDL_GetWindowDisplayMode() fails
if I don't call it. */
SDL_SetWindowSize(window, wanted_mode.w, wanted_mode.h);
if (SDL_GetWindowDisplayMode(window, &real_mode) != 0)
{
SDL_DestroyWindow(window);
window = NULL;
common->Warning("Can't get display mode: %s\n", SDL_GetError());
return false; // trying other color depth etc is unlikely to help with this issue
}
if ((real_mode.w != parms.width) || (real_mode.h != parms.height))
{
SDL_DestroyWindow(window);
window = NULL;
common->Warning("Still in wrong display mode: %ix%i instead of %ix%i\n",
real_mode.w, real_mode.h, parms.width, parms.height);
return false; // trying other color depth etc is unlikely to help with this issue
}
}
}
context = SDL_GL_CreateContext(window);
if (SDL_GL_SetSwapInterval(r_swapInterval.GetInteger()) < 0)

View file

@ -360,6 +360,9 @@ int CCamWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) {
//qwglMakeCurrent (hDC, win32.hGLRC);
if( qwglMakeCurrent ( hDC, win32.hGLRC ) == FALSE ) {
common->Warning("wglMakeCurrent failed: %d", ::GetLastError());
if ( r_multiSamples.GetInteger() > 0 ) {
common->Warning("\n!!! Remember to set r_multiSamples 0 when using the editor !!!\n");
}
}
if ((g_qeglobals.d_font_list = qglGenLists(256)) == 0) {