Pixels vs density independent units

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
Oddstream
Prole
Posts: 2
Joined: Mon Mar 28, 2022 12:01 pm

Pixels vs density independent units

Post by Oddstream »

The wiki states "Most LÖVE functions return values and expect arguments in terms of pixels rather than density-independent units.
The units of love.graphics.getWidth, love.graphics.getHeight, love.mouse.getPosition, mouse events, love.touch.getPosition, and touch events are always in terms of pixels."

So, I'm nervous about the word "most".

Q1. How can I tell which LÖVE functions use pixels, and which use density-independent units?

Q2. Assume I'm making an app that should work on mobiles as well as desktops. Would you recommend I use pixels or density-independent units internally?

https://github.com/oddstream/lsol
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Pixels vs density independent units

Post by pgimeno »

I'm not sure what the wiki says is correct; I think it's the other way around, unless you define c.window.usedpiscale = false in love.conf.

I think "most" includes all functions requiring graphical coordinates except those where it's obvious that the coordinates are the other ones, e.g. love.window.fromPixels obviously requires coordinates in pixels, while love.window.toPixels obviously requires coordinates in device-independent units.

As for what to use internally, it's hard to say but most likely DIU will be better in the long run.
User avatar
slime
Solid Snayke
Posts: 3131
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Pixels vs density independent units

Post by slime »

pgimeno wrote: Sun Aug 14, 2022 6:58 pm I'm not sure what the wiki says is correct; I think it's the other way around, unless you define c.window.usedpiscale = false in love.conf.
love.graphics APIs (except those with "Pixel" in the name, like Texture:getPixelDimensions) return DPI-scaled a.k.a. density independent units, unless t.window.usedpiscale = false.

ImageData (via the love.image module) is the main thing that only uses pixels, since it doesn't interact with the screen. Pixel shaders also use pixels for things like the pixel coordinate value.

The love.window.toPixels wiki page (where the quote is from) is outdated - love used to only use pixels, but that changed in love 11, and that API page hasn't been updated.
Post Reply

Who is online

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