Re scaling and Resolutions

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
xDVexan
Prole
Posts: 6
Joined: Sun Jan 27, 2019 1:33 am

Re scaling and Resolutions

Post by xDVexan »

So, I have been looking for a few hours now trying to find how to scale things properly. I can't find anything helpful and most things don't work. Is there a lib for rescaling? I know LOVE has the love.graphics.scale() func. but It doesn't seem to work well.
Lucio, Head Developer
Haecia
Official Haecia Website
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: Re scaling and Resolutions

Post by pgimeno »

That's not very specific. love.graphics.scale() does what it's supposed to do, but I'm not sure what you're expecting to get.

- If you expect pixelation instead of interpolation, you can set love.graphics.setDefaultFilter("nearest", "nearest").
- If you are trying to reduce images to under 50% of their size, you'll need to activate mipmaps for them to look good, and the first parameter of setDefaultFilter should be kept at "linear".
- If you're rendering text and you want it to not look pixelated or blurred, you need to create fonts appropriate to the resolution you choose.
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Re scaling and Resolutions

Post by ivan »

Sure, the scale function works perfectly you just have to study the documentation to figure out how it works.
Now there are more difficult problems involved with scaling, especially if want to avoid stretching, etc.
Another solution is to use a scene graph:
https://github.com/2dengine/love.scene
With the scene graph, you are basically rendering everything to a "viewport" which can be scaled and resized automatically.
Last edited by ivan on Sat Dec 11, 2021 8:26 am, edited 2 times in total.
crystal
Prole
Posts: 15
Joined: Sat Sep 30, 2017 9:53 pm

Re: Re scaling and Resolutions

Post by crystal »

simply do

myW, myH = 500, 900
W, H = love.graphics.getDimensions()
scaleW, scaleH = W/myW, H/myH
...

love.draw()
love.graphics.push()
love.graphics.scale(scaleW,scaleW)
--draw game stuff
love.graphics.pop()
end

if you want to avoid stretching you must use same scaling factor for width and height
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Re scaling and Resolutions

Post by zorg »

crystal wrote: Mon Jan 28, 2019 3:51 pm myW, myH = 500, 900
W, H = love.graphics.getDimensions()
scaleW, scaleH = W/myW, H/myH
...

love.draw()
love.graphics.push()
love.graphics.scale(scaleW,scaleW)
--draw game stuff
love.graphics.pop()
end
You are assuming that the height is larger than the width; that's usually only the case with phones, not desktops; a better method would be to have one scaling variable that uses the minimum of W/myW and H/myH (if you want dynamic letter/pillar-boxing; use maximum if you want to cut off the excess on the larger axis), because that's a better solution.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
xDVexan
Prole
Posts: 6
Joined: Sun Jan 27, 2019 1:33 am

Re: Re scaling and Resolutions

Post by xDVexan »

crystal wrote: Mon Jan 28, 2019 3:51 pm simply do

myW, myH = 500, 900
W, H = love.graphics.getDimensions()
scaleW, scaleH = W/myW, H/myH
...

love.draw()
love.graphics.push()
love.graphics.scale(scaleW,scaleW)
--draw game stuff
love.graphics.pop()
end

if you want to avoid stretching you must use same scaling factor for width and height
Forgot about this post, thanks for all the great replies! I am using this and it works perfectly!
Lucio, Head Developer
Haecia
Official Haecia Website
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 193 guests