Page 1 of 1
Recognising the screen on which the app is launched?
Posted: Tue Oct 29, 2024 5:45 pm
by Joubarbe
I've released a game on Steam, and two players using portable consoles (Asus ROG Ally) are having resolution problems. The app is drawn on a Windows Canvas and what they see is only the top left of the screen.
Here is the bug report.
What I do in my app is this:
Code: Select all
Define window_flags = #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget
Define window_width = \misc\window_width
Define window_height = \misc\window_height
If \misc\full_screen_mode = #True
ExamineDesktops()
window_width = DesktopWidth(0)
window_height = DesktopHeight(0)
\misc\window_width = window_width
\misc\window_height = window_height
window_flags = #PB_Window_BorderLess
EndIf
OpenWindow(#WINDOW_MAIN, 0, 0, window_width, window_height, "", window_flags)
SetWindowColor(#WINDOW_MAIN, \default_colors\terminal_background)
CanvasGadget(#CANVAS_MAIN, 0, 0, window_width, window_height, #PB_Canvas_Keyboard)
SetActiveGadget(#CANVAS_MAIN)
\misc being a data structure loaded from a .json settings file.
Weird things is that both devices are in 1920*1080. Any idea?
Re: Recognising the screen on which the app is launched?
Posted: Tue Oct 29, 2024 6:28 pm
by #NULL
Maybe check if you have to take desktop scaling into account (DPI aware?) I don't really know, just an idea.
Re: Recognising the screen on which the app is launched?
Posted: Tue Oct 29, 2024 6:53 pm
by JHPJHP
Hi Joubarbe,
I don't know anything about Steam, are you able to use Windows API's in your game?
Re: Recognising the screen on which the app is launched?
Posted: Tue Oct 29, 2024 6:58 pm
by Bisonte
In PC Requirements is : Windows 10 as os ... so I would say yes.
Re: Recognising the screen on which the app is launched?
Posted: Tue Oct 29, 2024 7:02 pm
by JHPJHP
Hi Bisonte,
Thank you for the information.
I'll cobble together a bunch of scripts I have that may help Joubarbe.
Re: Recognising the screen on which the app is launched?
Posted: Tue Oct 29, 2024 7:06 pm
by Joubarbe
Thanks JHPJHP.
Code: Select all
IncludeFile "includes\SetDpiAwareness.pbi"
What do I do with that?
Re: Recognising the screen on which the app is launched?
Posted: Tue Oct 29, 2024 7:23 pm
by JHPJHP
Hi Joubarbe,
Sorry about that... here is a temporary link to the previous scripts and a bunch more:
Monitor Stuff
Re: Recognising the screen on which the app is launched?
Posted: Tue Oct 29, 2024 7:36 pm
by Joubarbe
So I've just tried with 125% scaling and I can reproduce the bug. No idea how to fix that though; get the scale factor and change the resolution? The thing is my app is kinda like a terminal; it's a 2D array where each cell is a letter or symbol. So the whole scaling is made out of the font size, which is forced to always be the same so that all my UI looks always the same in all resolutions. I really didn't anticipate DPI awareness (rookie mistake I suppose!).
Re: Recognising the screen on which the app is launched?
Posted: Tue Oct 29, 2024 7:46 pm
by JHPJHP
Hi Joubarbe,
Try SetDpiAwareness.pbi separately, adding it as an IncludeFile to your program.
• Make sure DPI-Awareness is not checked under Compiler Options.
Take the last line of the include file and place it near the top of your program.
Change the parameter to one of the following... test them all including scaling options:
• #DPI_AWARENESS_CONTEXT_UNAWARE
• #DPI_AWARENESS_CONTEXT_SYSTEM_AWARE
• #DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
• #DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
• #DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED
If any of the settings work, add a condition-based argument using the include file only when required.
Re: Recognising the screen on which the app is launched?
Posted: Tue Oct 29, 2024 8:04 pm
by Joubarbe
Well the default one seems to work just fine. I've just included SetDpiAwareness.pbi and didn't modify anything.
Amazing, thank you very much!
Re: Recognising the screen on which the app is launched?
Posted: Tue Oct 29, 2024 8:08 pm
by ChrisR
Hi Joubarbe,
Another way to do it, is to keep DPIaware compiler options and then disable PB's scaling on runtime
By adding this at the beginning of the program, your game will run as if it were at 100% Scaling:
Code: Select all
; Keep DPIaware compiler options and then disable PB's scaling on runtime, with it's global variables
Import ""
PB_Desktop_DPIX.l
PB_Desktop_DPIY.l
PB_Desktop_ResolutionX.d
PB_Desktop_ResolutionY.d
EndImport
CompilerIf #PB_Compiler_Backend = #PB_Backend_Asm
!mov dword [PB_Compiler_DPIAware], 0
CompilerElse
Import ""
PB_Compiler_DPIAware.l
EndImport
PB_Compiler_DPIAware = 0
CompilerEndIf
PB_Desktop_DPIX = 96 : PB_Desktop_DPIY = 96
PB_Desktop_ResolutionX = 1.0 : PB_Desktop_ResolutionY = 1.0
Re: Recognising the screen on which the app is launched?
Posted: Tue Oct 29, 2024 8:17 pm
by Joubarbe
Thank you ChrisR. I've already uploaded the previous solution on Steam

But it's nice to have different solutions anyway.
So the solution to user-defined DPI scaling is to overwrite it...? It seems counter intuitive to me. Do the big games actually do that as well? Why does Windows keep this on for full screen games? I just never thought about this scaling option in Windows.
Re: Recognising the screen on which the app is launched?
Posted: Tue Oct 29, 2024 8:29 pm
by ChrisR
I have not tested JHPJHP's SetDpiAwareness and I assume it's fine, as usual
But without DPI-Awareness (unchecked) in compiler option, you need to check that the default windows zoom is not automatically apply.
Otherwise, you risk having images and text that are a little blurry.
Re: Recognising the screen on which the app is launched?
Posted: Tue Oct 29, 2024 9:04 pm
by JHPJHP
Hi Joubarbe,
You are most welcome.
-----------------
Hi ChrisR,
That's a nice snippet of code. Thank you.
I was hoping you posted a magic bullet to solve all DPI needs, but it worked almost the same as the solution I posted, except with less options.
I tested your solution with my
GIF Toolkit, but the window and controls were scaled to an almost unusable size, which is why I suggested that
Joubarbe test all settings including the various scaling options: 100%, 125%, 150%, etc.
When using my IncludeFile I found for text-based programs that
#DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED worked best, but the only way to be sure was to test, test and test again... even then you can't be 100% confident that the solution will work for all systems.
Re: Recognising the screen on which the app is launched?
Posted: Tue Oct 29, 2024 11:17 pm
by ChrisR
You're right, the only way to be sure was to test, test and test again... even then you can't be 100% confident that the solution will work for all systems.
Microsoft doesn't make things easy with their DPI-Aware solutions.