Page 1 of 1

Get the screen DPI/PPI

Posted: Tue Jul 27, 2021 8:05 am
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 ?

Re: Get the screen DPI/PPI

Posted: Tue Jul 27, 2021 8:58 am
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

Re: Get the screen DPI/PPI

Posted: Tue Jul 27, 2021 6:05 pm
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.

Re: Get the screen DPI/PPI

Posted: Fri Jul 30, 2021 11:22 pm
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.