Skip to content

Commit 481c4da

Browse files
committed
SDL - Possible fix for Windowed resolution
1 parent 42b5014 commit 481c4da

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

neo/sys/sdl/sdl_glimp.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ idCVar r_useOpenGL32( "r_useOpenGL32", "1", CVAR_INTEGER, "0 = OpenGL 3.x, 1 = O
6262
// RB end
6363

6464
extern idCVar r_fullscreen;
65+
extern idCVar swf_cursorDPI;
6566

6667
static bool grabbed = false;
6768

@@ -279,6 +280,7 @@ bool GLimp_Init( glimpParms_t parms )
279280

280281
// DG: set display num for fullscreen
281282
int windowPos = SDL_WINDOWPOS_UNDEFINED;
283+
int windowPosY = SDL_WINDOWPOS_UNDEFINED;
282284
if( parms.fullScreen > 0 )
283285
{
284286
int count = 0;
@@ -293,8 +295,12 @@ bool GLimp_Init( glimpParms_t parms )
293295
// -1 because SDL starts counting displays at 0, while parms.fullScreen starts at 1
294296
SDL_DisplayID displayID = displays[parms.fullScreen - 1];
295297
windowPos = SDL_WINDOWPOS_UNDEFINED_DISPLAY( ( displayID ) );
298+
windowPosY = SDL_WINDOWPOS_UNDEFINED_DISPLAY( ( displayID ) );
296299
}
297300
SDL_free(displays);
301+
} else if (parms.fullScreen == 0) {
302+
windowPos = parms.x;
303+
windowPosY = parms.y;
298304
}
299305
// TODO: if parms.fullScreen == -1 there should be a borderless window spanning multiple displays
300306
/*
@@ -307,7 +313,7 @@ bool GLimp_Init( glimpParms_t parms )
307313
SDL_PropertiesID props = SDL_CreateProperties();
308314
SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, ENGINE_NAME);
309315
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_X_NUMBER, windowPos);
310-
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_Y_NUMBER, windowPos);
316+
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_Y_NUMBER, windowPosY);
311317
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, parms.width);
312318
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, parms.height);
313319
// For window flags you should use separate window creation properties,
@@ -367,13 +373,12 @@ bool GLimp_Init( glimpParms_t parms )
367373
glConfig.stencilBits = tstencilbits;
368374

369375
// RB begin
370-
glConfig.displayFrequency = 60;
376+
glConfig.displayFrequency = parms.displayHz;
371377
glConfig.isStereoPixelFormat = parms.stereo;
372378
glConfig.multisamples = parms.multiSamples;
373-
374379
glConfig.pixelAspect = 1.0f; // FIXME: some monitor modes may be distorted
375380
// should side-by-side stereo modes be consider aspect 0.5?
376-
381+
swf_cursorDPI.SetFloat(SDL_GetWindowPixelDensity(window));
377382
// RB end
378383

379384
break;
@@ -520,8 +525,7 @@ static bool SetScreenParmsFullscreen( glimpParms_t parms )
520525

521526
static bool SetScreenParmsWindowed( glimpParms_t parms )
522527
{
523-
SDL_SetWindowSize( window, parms.width, parms.height );
524-
SDL_SetWindowPosition( window, parms.x, parms.y );
528+
525529

526530
// if we're currently in fullscreen mode, we need to disable that
527531
if( SDL_GetWindowFlags( window ) & SDL_WINDOW_FULLSCREEN )
@@ -532,6 +536,9 @@ static bool SetScreenParmsWindowed( glimpParms_t parms )
532536
return false;
533537
}
534538
}
539+
SDL_SetWindowSize( window, parms.width, parms.height );
540+
SDL_SetWindowPosition( window, parms.x, parms.y );
541+
535542
return true;
536543
}
537544

@@ -557,6 +564,7 @@ bool GLimp_SetScreenParms( glimpParms_t parms )
557564
common->Warning( "GLimp_SetScreenParms: fullScreen -1 (borderless window for multiple displays) currently unsupported!" );
558565
return false;
559566
}
567+
SDL_SyncWindow(window);
560568

561569
// Note: the following stuff would also work with SDL1.2
562570
SDL_GL_SetAttribute( SDL_GL_STEREO, parms.stereo ? 1 : 0 );
@@ -566,10 +574,10 @@ bool GLimp_SetScreenParms( glimpParms_t parms )
566574

567575
glConfig.isFullscreen = parms.fullScreen;
568576
glConfig.isStereoPixelFormat = parms.stereo;
569-
glConfig.nativeScreenWidth = parms.width > 0 ? parms.width : 1280;
570-
glConfig.nativeScreenHeight = parms.height > 0 ? parms.height : 720;
577+
SDL_GetWindowSizeInPixels( window, &glConfig.nativeScreenWidth, &glConfig.nativeScreenHeight );
571578
glConfig.displayFrequency = parms.displayHz;
572579
glConfig.multisamples = parms.multiSamples;
580+
swf_cursorDPI.SetFloat(SDL_GetWindowPixelDensity(window));
573581

574582
return true;
575583
}

0 commit comments

Comments
 (0)