Recognising the screen on which the app is launched?

Just starting out? Need help? Post your questions and find answers here.
Joubarbe
Enthusiast
Enthusiast
Posts: 714
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Recognising the screen on which the app is launched?

Post 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?
#NULL
Addict
Addict
Posts: 1499
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Recognising the screen on which the app is launched?

Post by #NULL »

Maybe check if you have to take desktop scaling into account (DPI aware?) I don't really know, just an idea.
User avatar
JHPJHP
Addict
Addict
Posts: 2267
Joined: Sat Oct 09, 2010 3:47 am

Re: Recognising the screen on which the app is launched?

Post by JHPJHP »

Hi Joubarbe,

I don't know anything about Steam, are you able to use Windows API's in your game?

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
User avatar
Bisonte
Addict
Addict
Posts: 1320
Joined: Tue Oct 09, 2007 2:15 am

Re: Recognising the screen on which the app is launched?

Post by Bisonte »

In PC Requirements is : Windows 10 as os ... so I would say yes.
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
User avatar
JHPJHP
Addict
Addict
Posts: 2267
Joined: Sat Oct 09, 2010 3:47 am

Re: Recognising the screen on which the app is launched?

Post by JHPJHP »

Hi Bisonte,

Thank you for the information.

I'll cobble together a bunch of scripts I have that may help Joubarbe.
Last edited by JHPJHP on Tue Oct 29, 2024 7:39 pm, edited 1 time in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Joubarbe
Enthusiast
Enthusiast
Posts: 714
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: Recognising the screen on which the app is launched?

Post by Joubarbe »

Thanks JHPJHP.

Code: Select all

IncludeFile "includes\SetDpiAwareness.pbi"
What do I do with that?
User avatar
JHPJHP
Addict
Addict
Posts: 2267
Joined: Sat Oct 09, 2010 3:47 am

Re: Recognising the screen on which the app is launched?

Post by JHPJHP »

Hi Joubarbe,

Sorry about that... here is a temporary link to the previous scripts and a bunch more: Monitor Stuff
Last edited by JHPJHP on Tue Oct 29, 2024 9:35 pm, edited 2 times in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Joubarbe
Enthusiast
Enthusiast
Posts: 714
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: Recognising the screen on which the app is launched?

Post 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!).
User avatar
JHPJHP
Addict
Addict
Posts: 2267
Joined: Sat Oct 09, 2010 3:47 am

Re: Recognising the screen on which the app is launched?

Post 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.
Last edited by JHPJHP on Tue Oct 29, 2024 9:37 pm, edited 2 times in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Joubarbe
Enthusiast
Enthusiast
Posts: 714
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: Recognising the screen on which the app is launched?

Post 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!
User avatar
ChrisR
Addict
Addict
Posts: 1484
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Recognising the screen on which the app is launched?

Post 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
Joubarbe
Enthusiast
Enthusiast
Posts: 714
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: Recognising the screen on which the app is launched?

Post 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.
User avatar
ChrisR
Addict
Addict
Posts: 1484
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Recognising the screen on which the app is launched?

Post 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.
User avatar
JHPJHP
Addict
Addict
Posts: 2267
Joined: Sat Oct 09, 2010 3:47 am

Re: Recognising the screen on which the app is launched?

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

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
User avatar
ChrisR
Addict
Addict
Posts: 1484
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Recognising the screen on which the app is launched?

Post 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.
Post Reply