We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4070 - SDL 2 Any Desktop Resolution query returns wrong areas
Summary: SDL 2 Any Desktop Resolution query returns wrong areas
Status: ASSIGNED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.7
Hardware: x86_64 Windows 10
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-02-01 05:12 UTC by hubert.vansteenhuyse
Modified: 2018-06-23 13:35 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description hubert.vansteenhuyse 2018-02-01 05:12:02 UTC
SDL 2.0.7.0 and Windows 10 x86_64.

When the Custom Scaling (right click desktop => Display Settings => Scale and layout) is set to 125% or 150% instead of the 100%, all the methods:
SDL_GetDesktopDisplayMode, SDL_GetCurrentDisplayMode, SDL_GetDisplayBounds... return a smaller screen resolution than the actual one.

Furthermore when you create an OpenGL window SDL_WINDOW_FULLSCREEN in the same conditions the window are doesn't fit the visible area on the screen, (apparently SDL_WINDOW_FULLSCREEN_DESKTOP does a slightly better job than SDL_WINDOW_FULLSCREEN when 150%).

Hints like SDL_HINT_VIDEO_HIGHDPI_DISABLED or window flags SDL_WINDOW_ALLOW_HIGHDPI do not change anything.
Forcing the resolution to the correct one doesn't help either. 

My code runs on windows and linux for years now without problems, I ported it to SDL 2 about 2 years ago.

I hope that my explanation is clear enough.

Thank you for this marvellous API you have been offering us for years, it simply is a Great API!
 
Hubert.
Comment 1 Eric Wasylishen 2018-02-03 23:05:21 UTC
I think my windows highdpi patch would fix this; I need to fix some merge conflicts and update it (it hasn't been updated since last October).
https://github.com/ericwa/SDL-mirror/blob/windows-highdpi

Here is a workaround to force DPI awareness:
https://discourse.libsdl.org/t/sdl-getdesktopdisplaymode-resolution-reported-in-windows-10-when-using-app-scaling/22389/4


One key point: on Windows, if a process is non-DPI-aware and there is a scale factor >100%, you can't enter the fullscreen mode that is the "native" desktop resolution in pixels (either with SDL_WINDOW_FULLSCREEN or SDL_WINDOW_FULLSCREEN_DESKTOP).  e.g. suppose a 2880x1800 pixel monitor using 200% scaling (giving a virtual size of 1440x900). If an app is not DPI aware, it's impossible to change to 2880x1800 pixel fullscreen mode. You can change to other modes, though (1920x1200 pixels etc.)
see my comments at: https://github.com/ericwa/SDL-mirror/blob/windows-highdpi/src/video/windows/SDL_windowsmodes.c#L532

Since accessing the "native" fullscreen mode is IMO a feature that I expect to always work, I think most SDL apps should be DPI aware (?)
Comment 2 hubert.vansteenhuyse 2018-06-23 13:35:23 UTC
I use the SDL_win32_main.cpp provided by SDL and compile it in my project.

Eric was right, one just has to enable the high DPI awareness (see https://msdn.microsoft.com/en-us/library/windows/desktop/ms633543(v=vs.85).aspx).

Alternatively, changing the compatibility settings from Windows 10 on the executable itself without the changes in the source code also works.
Right click on the shortcut->Properties->Compatibility->Change high DPI settings->High DPI scaling override


Adding the following in function WinMain solved my problem:

	//enable high DPI awareness
	HMODULE 		hUser32 = LoadLibrary("User32.dll");
	BOOL WINAPI (CALLBACK* dllSetProcessDPIAware)(void) = 0;
	if(hUser32){
		dllSetProcessDPIAware = GetProcAddress(hUser32, "SetProcessDPIAware");
		if(dllSetProcessDPIAware) dllSetProcessDPIAware();
		FreeLibrary(hUser32);
	}


        ... loading "DDRAW.DLL" SDL code ...