FS#6056 - 4K Resolution not detected

Attached to Project: OpenTTD
Opened by sigi (sigii) - Monday, 07 July 2014, 19:22 GMT
Last edited by Charles Pigott (LordAro) - Friday, 18 August 2017, 22:06 GMT
Type Bug
Category Core
Status With patch
Assigned To No-one
Operating System Windows
Severity Medium
Priority Normal
Reported Version 1.4.1
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 0
Private No


I have a 4k resolution display and openttd is not detecting it.

It only offers 1920x1200 as max resolution.

I'm able to resize the window without any problems in non-fullscreen mode.
This task depends upon

Comment by Alberth (Alberth) - Friday, 11 July 2014, 16:27 GMT
We use an external library for handling screens and selecting screen resolution. OpenTTD just uses whatever the library provides to us. You may want to look higher upstream, and check whether that library has any known issues w.r.t. high resolution screens.
Comment by Remko Bijker (Rubidium) - Sunday, 27 July 2014, 14:40 GMT
OpenTTD asks the operating systems for the supported resolutions. If that function does not return anything with width >= 640 and height >= 480, then it will use a fallback list of resolutions.

The only conclusion I can make is that Windows is not returning an useful resolution with EnumDisplaySettings.
Comment by Peter (gpsoft) - Tuesday, 21 October 2014, 15:28 GMT
I tried the function on my computer, which has also 4k screen.
The list of resolutions is attached.

But if you check the MDSN documentation about EnumDisplaySettings, it says:

"Note Apps that you design to target Windows 8 and later can no longer query or set display modes that are less than 32 bits per pixel (bpp); these operations will fail. These apps have a compatibility manifest that targets Windows 8. Windows 8 still supports 8-bit and 16-bit color modes for desktop apps that were built without a Windows 8 manifest; Windows 8 emulates these modes but still runs in 32-bit color mode."

As you can see in the list, there is only 32 bit resolution from the function (I am also using Windows 8).
So in the function "static void FindResolutions()" we should test if the operating system is Windows 8 and later, if yes then we have to set "bpp" to 32 even if we are intended to use 8bit resolution.
I guess it won't be hard to make a patch, but if anyone interested, I can try to make it, just let me know.
Comment by frosch (frosch) - Tuesday, 21 October 2014, 17:20 GMT
In that case, can you please test the nightly.
The nightly (i.e. 1.5) defaults to 32bpp video modes.
Comment by Peter (gpsoft) - Wednesday, 22 October 2014, 20:32 GMT
I tested the nightly, it is fine.
But I think we can do it properly also on different video modes. I made a small fix for this problem, the patch is attached (I will try to run it in the debugger after having a setup in Visual Studio).
I tested this on Windows 8.1 and Windows 7 (after compiling with MinGW) and on both it works fine and picks up the real resolutions.
Feel free to modify it if you are not happy with the way how I did it.

The detection of windows version is not a currently recommended way but I couldn't do it that way, _WIN32_WINNT is probably not defined and for the new functions it needs to have a minimal level of 0x0500. But it works fine, might be deprecated in a future versions of Windows.