NoHighDPI - Disable High DPI on Android devices

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
FloatingBanana
Prole
Posts: 22
Joined: Sat Mar 02, 2019 4:57 pm
Contact:

NoHighDPI - Disable High DPI on Android devices

Post by FloatingBanana »

It's my first post in this community, sorry for anything :3

High DPI scaling on Android is very annoying, especially when you use both the Windows and Android to work with the same project.

There is a trick to solve this using love.window.fromPixels and love.window.toPixels, so I made this library to do this for you!

How to use

You just need to do this:

Code: Select all

nohdpi = require "nohighdpi"

function love.load()
    --Pass "graphics", "mouse" and/or "touch"
    --as arguments to replace the given modules.
    --If you don't give any arguments, then
    --all modules will be replaced.
    nohighdpi:replace()
end
And voilà, you can use LÖVE normally without worrying about DPI scaling!

Manual mode

You can also use this library manually:

Code: Select all

nohdpi = require "nohighdpi"

function love.load()

end

function love.draw()
    --You can optionally give a custom resolution
    nohdpi:start(800, 600)
    
    --Draw your things here
    love.graphics.circle("line", nohdpi:mouseX(), nohdpi:mouseY(), 5, 100)

    --You can also change the resolution
    nohdpi:rescale(1000, 675)
    
    nohdpi:stop()
end

function love.update(dt)

end

function love.mousepressed(x, y, button, isTouch)
    x, y = nohdpi:toResized(x, y)
    
    --Use it normally. The same goes to mousereleased, touchpressed, touchreleased...
end
Using only "graphics" manually

Code: Select all

nohdpi = require "nohighdpi"

function love.load()
    nohdpi:replace("mouse", "touch")
end

function love.draw()
    nohdpi:start()

    love.graphics.circle("line", love.mouse.getX(), love.mouse.getY(), 5, 100)
 
    nohdpi:stop()
end

function love.update(dt)

end

function love.mousepressed(x, y, button, isTouch)
    
end
Github page

Code: Select all

if anyMistake(self.english) then
    print("Sorry, english is not my first language")
end
User avatar
pgimeno
Party member
Posts: 3549
Joined: Sun Oct 18, 2015 2:58 pm

Re: NoHighDPI - Disable High DPI on Android devices

Post by pgimeno »

It's nice that you made this library; I've struggled with this myself. Note however that the next version (11.3 hopefully) will have a built-in setting for this. https://bitbucket.org/rude/love/commits ... 53a78b6eb0
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 84 guests