Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HiDPI scaling #301

Open
AlexJakeGreen opened this issue Sep 8, 2022 · 13 comments
Open

HiDPI scaling #301

AlexJakeGreen opened this issue Sep 8, 2022 · 13 comments
Labels
enhancement New feature or request

Comments

@AlexJakeGreen
Copy link

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

@Try
Copy link
Owner

Try commented Feb 8, 2023

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.

@ezamelczyk
Copy link

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

@wiktorskowronski
Copy link

wiktorskowronski commented Apr 14, 2023

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);
  }

@Try Try added the enhancement New feature or request label Jul 10, 2023
@lectricas
Copy link

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

@Try
Copy link
Owner

Try commented Nov 13, 2023

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.

@lectricas
Copy link

@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.

@Try
Copy link
Owner

Try commented Nov 14, 2023

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.

@dreimer1986
Copy link

dreimer1986 commented Nov 15, 2023

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.

@Nindaleth
Copy link
Contributor

@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.

@lectricas
Copy link

@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%?

@Nindaleth
Copy link
Contributor

Nindaleth commented Nov 15, 2023

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).

@sjavora
Copy link
Contributor

sjavora commented Nov 15, 2023

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

@lectricas
Copy link

lectricas commented Nov 19, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

8 participants