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 3433 - SDL_GetCurrentDisplayMode returns incorrect resolution for DPI scale != 100%
Summary: SDL_GetCurrentDisplayMode returns incorrect resolution for DPI scale != 100%
Status: RESOLVED ABANDONED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.0
Hardware: x86_64 Windows 10
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-23 21:59 UTC by Ethan Lee
Modified: 2018-09-05 16:44 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 Ethan Lee 2016-09-23 21:59:55 UTC
We've encountered a really odd case on Windows where GetCurrentDisplayMode doesn't actually report the desktop resolution. Using this test program...

int main(int argc, char **argv)
{
    SDL_DisplayMode mode;
    int modes;
    int i;

    SDL_Init(SDL_INIT_VIDEO);
    modes = SDL_GetNumDisplayModes(0);
    for (i = 0; i < modes; i += 1)
    {
        SDL_GetDisplayMode(0, i, &mode);
        printf("%d %d\n", mode.w, mode.h);
    }
    SDL_GetCurrentDisplayMode(0, &mode);
    printf("%d %d\n", mode.w, mode.h);
    SDL_Quit();
    return 0;
}

... you'll get the following on a LG 55EG9100 running at 1920x1080, using an AMD GPU on Windows 10:

1920 1080
1920 1080
1920 1080
1920 1080
1920 1080
1920 1080
1776 1000
1776 1000
1776 1000
1776 1000
1776 1000
1680 1050
1680 1050
1680 1050
1680 1050
1680 1050
1680 1050
1600 900
1600 900
1600 900
1600 900
1600 900
1360 768
1280 1024
1280 960
1280 768
1280 720
1280 720
1152 864
1152 648
1152 648
1024 768
800 600
720 576
720 480
720 480
640 480
640 480
1280 720

The expected behavior is that we get '1920 1080' as the last line instead of '1280 720'.
Comment 1 Hayk Shahparonyan 2016-10-29 22:57:39 UTC
The problem should be due to Windows DPI scaling. If you've set you resolution to 1920x1080 and it was scaled by 150%, you will get 1280x720 reported to SDL. I either did not get any solution for this either, so I hope to see some actions (like an API to get real resolution) from developers.
Comment 2 Ethan Lee 2016-10-31 16:27:18 UTC
Looks like that was it. Is there any way for us to sidestep this issue, or is there a way we can query scale and adjust the resolution accordingly?
Comment 3 Alex Szpakowski 2016-10-31 16:42:03 UTC
I believe the "correct" approach (which would also benefit iOS and macOS) is to provide a new API to query the pixel size or scale factor for display modes, since if you're working with high dpi aware stuff it usually makes sense to know both the raw pixel dimensions and the pixel density scaled dimensions.
Comment 4 Ethan Lee 2018-09-05 16:44:44 UTC
Closing this since the issue is known to be fixed by either a manifest file or something like SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE), falling back to SetProcessDPIAware() for older Windows versions. Maybe SDL can provide an SDL_Windows_SetProcessDPIAware() function that automatically does all this, but the main thing is that this is technically intentional behavior on Windows' part.