Get the screen DPI/PPI

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
deb75
Prole
Posts: 38
Joined: Sun Apr 18, 2021 1:11 pm

Get the screen DPI/PPI

Post by deb75 »

Hello,

In my game development, I need to get the correspondance between one true unit screen distance (e.g. 1 inch or 1 centimeter)
and the number of pixels associated with this distance. This is because I need to zoom in/out some objects (images) but I
want them to be still visible.

There is the function love.windows.getDPIScale(), but it does not return what I want.

Is there anyway from love to get the DPI screen value ?

Actually, it would be cleaner to talk about the PPI (Pixel Per Inch).

Regards

EDIT :

I guess my question is a bit out of love scope.

I am not sure the DPI/PPI is accessible in windows, but at least one can calculate it with the screen dimension, e.g. 1600x1200 pixels,
and the screen diagonal, expressed as 13", 24", ...

So the more precise question would be : is it possible to retrieve the screen diagonal from love ?
deb75
Prole
Posts: 38
Joined: Sun Apr 18, 2021 1:11 pm

Re: Get the screen DPI/PPI

Post by deb75 »

At least, there is a programmatic way to get the screen dimensions in windows 10 shell :

Code: Select all

Get-WmiObject -Namespace root\wmi -Class WmiMonitorBasicDisplayParams 
which, among other things, outputs :
InstanceName : DISPLAY\MEI96A2\4&289d63ab&0&UID265988_0
MaxHorizontalImageSize : 29
MaxVerticalImageSize : 19

I personnally recognize the horizontal and vertical size in centimeters of my screen.

It should not be too difficult to wrap this powershell script into a lua subprocess and postprocess its output.

Regards
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: Get the screen DPI/PPI

Post by ReFreezed »

Yeah, this is a bit out of scope for LÖVE. You could just ask the user what the size is, if it's important.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Get the screen DPI/PPI

Post by pgimeno »

There's SDL_GetDisplayDPI, maybe you can access it using FFI. But I wouldn't trust the value too much. Perhaps to use it as a default to ask the user as ReFreezed suggested.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 6 guests