OpenGothic icon indicating copy to clipboard operation
OpenGothic copied to clipboard

HiDPI scaling

Open AlexJakeGreen opened this issue 3 years ago • 16 comments

It would be good if it possible to have a fractional scaling for texts/dialogs, menus and health/mana indicators on HiDPI screens.

AlexJakeGreen avatar Sep 08 '22 08:09 AlexJakeGreen

Short overview on existing solutions:

  1. Android way Have pixel-based api, but expose scale factor. Works, but trashes code with *dpi conversions.
  2. Windows way Hide all under the hood. All api that are claim to use pixels do scale-multiplication internally. Convenient, but doesn't fit 3D content.

Option 1

Quite bad for coding, since dpi scale will pollute all 2d code, and practically untestable - better not to use.

Option 2

Has issues as well: Swaphain should match physical size of parent window, otherwise scaling is not defined. So scaling on MainWindow is a problem. It's not exactly clear where scaling should be put in.

Try avatar Feb 08 '23 21:02 Try

Maybe for starters we could just change the resolution? We don't really need to run gothic at 4k

ezamelczyk avatar Feb 27 '23 20:02 ezamelczyk

For MacOS I just used scale factor, but it is rather dirty hack until we can change resolution.

/lib/Tempest/Engine/system/api/macosapi.mm

void Detail::ImplMacOSApi::onDidResize(void* hwnd, void* w) {
  auto      cb  = reinterpret_cast<Tempest::Window*>(hwnd);
  NSWindow* wnd = reinterpret_cast<NSWindow*>(w);

  NSRect    fr  = windowRect(wnd);
  fr = [wnd convertRectToBacking:fr];

  double scaleFactor = [wnd backingScaleFactor];
  SizeEvent sz{int32_t(fr.size.width/scaleFactor),int32_t(fr.size.height/scaleFactor)};
  MacOSApi::dispatchResize(*cb,sz);
  }

wiktorskowronski avatar Apr 14 '23 16:04 wiktorskowronski

Is there any way to scale dialogs for a starter? Any settings for that?

lectricas avatar Nov 13 '23 20:11 lectricas

Is there any way to scale dialogs for a starter? Any settings for that?

We are missing INTERFACE/scale flag from systempack at this moment - need to implement. for reference:

[INTERFACE]

Scale=0
; ... Automatic interface scaling, resolution 1024x768 used as base for autoscale algorithm.
; on (1) or (1.1 ... and higher), - Interface scaling in n-times on the discretion of the user.
; maximum value depend on vertical resolution.
; for exapmle, for 1920x1080 it will be 1080/512 = 2.10.
; for 3840x2160 it will be 2160/512 = 4.21.
; higher values will be readed as maximum value.
; off (0), - without scaling. Default is 1.

Except auto-scaling here is questionable - dpi based sceling, seems to be way better option.

Try avatar Nov 13 '23 23:11 Try

@Try maybe I can set resolution to 1360×768 or something? I really don't need a high res gothic 2. When I try to change resolution in settings, it changes something, but making the game kinda blurry, not squary.

lectricas avatar Nov 14 '23 19:11 lectricas

When I try to change resolution in settings, it changes something, but making the game kinda blurry, not squary.

it changes only rendering resolution for 3D and upscales it a bit during tonemapping phase.

Try avatar Nov 14 '23 22:11 Try

Just my 2 cents here. If you choose 1024x768 as base, why don't you just let it auto scale from that with DPI in mind? https://www.reddit.com/r/vulkan/comments/8jlgt2/surface_capabilities_and_dpi_scaling/ so it would be possible to get a DPI value to include in your calculation. For crazy ppl you could even add Scale=2 for manual factor setting and another value for your favorite factor. Everyone would be happy by that. Maybe I am not gaming enough anymore, but I barely ever heard of a game that decided to follow the DPI factor Windows is set to.

dreimer1986 avatar Nov 15 '23 08:11 dreimer1986

@lectricas as a temporary workaround I can suggest switching your whole system to a lower res before starting the game; OpenGothic will reuse the current system resolution.

Nindaleth avatar Nov 15 '23 10:11 Nindaleth

@Nindaleth I've downlaoded EasyRes from app store to change resolution and set 1280x800 and run the game. Then I got the white screen. Turning resolution back to default reversed the problem. Have you done this procedure? Any steps how to make it work 100%?

lectricas avatar Nov 15 '23 12:11 lectricas

App Store? Is it not possible on macOS to change the system resolution from an official system dialog? Sorry, I only have experience with Windows and Linux OSs where this is built-in and just works (no sarcasm intended).

Nindaleth avatar Nov 15 '23 13:11 Nindaleth

Of course it's possible. Apple just loves to hide the actual numbers (you can see them on mouseover).

Screenshot 2023-11-15 at 14 57 20

sjavora avatar Nov 15 '23 13:11 sjavora

Ok, guys, I gave it another try and put @wiktorskowronski fix and it works, although all the items are messed up:

Screenshot 2023-11-20 at 21 24 13

UPD: So, for those who just want to play the game, modify this method:

void InventoryRenderer::drawItem(int x, int y, int w, int h, const ::Item& item) {
  x = x*2;
  y = y*2;
  w = w*2;
  h = h*2;
  ...
}

together with a fix from @wiktorskowronski

What we've done here is increased the position and size of the items by 2, because with @wiktorskowronski fix we scaled down everything.

backingScaleFactor is 2 by default. https://developer.apple.com/documentation/appkit/nswindow/1419459-backingscalefactor

lectricas avatar Nov 19 '23 22:11 lectricas