Page 1 of 1
[Solved]Canvas and multiple resolutions
Posted: Fri Oct 04, 2013 8:46 pm
by xCode195
Hello everyone,
I have an issue with using multiple resolutions and canvases.The problem is that when I use canvases everything gets scaled too much,either its too small or too big.I have attached example .love files below.I am using this snippet for resolutions
http://love2d.org/forums/viewtopic.php?t=12819
I sense that the solution for this is simple,but for the life of me I can't figure it out
...
Thanks!
Re: Canvas and multiple resolutions
Posted: Tue Oct 08, 2013 4:52 pm
by xCode195
Sorry for bumping but i could really use some input on this before I go further into development and this becomes unfixable
.
Thanks again!
Re: Canvas and multiple resolutions
Posted: Tue Oct 08, 2013 6:52 pm
by raidho36
Try swapping around screen and surface dimensions when passing to the ratio computing function in the beginning.
Re: Canvas and multiple resolutions
Posted: Tue Oct 08, 2013 7:35 pm
by xCode195
raidho36 wrote:Try swapping around screen and surface dimensions when passing to the ratio computing function in the beginning.
Thanks for responding but,
if you meant these values:
Then it didn't help,also these values must stay that way because gw,gh are values that the game was originally meant to be run on and sw,sh are values of the user set resolution.That means that everything should be at the same place independent of resolution(with black bars on the bottom and top if needed).
Everything works fine(e.g. everything is in it's place independent of resolution) until I start using canvases,even if i don't do anything with the canvas other than draw that same image on it and then draw the canvas itself...
Re: Canvas and multiple resolutions
Posted: Tue Oct 08, 2013 8:13 pm
by raidho36
Oh, I see.
Apparently, the "library" applies some kind of global transformation. When you draw without a canvases it works as expected. When draw onto canvas, it would draw everything scaled, as with no canvases, predictably. However, you might intent no scaling for drawing onto canvas, but this will happen anyway unless you manually disable that. And this seems to be your problem.
Re: Canvas and multiple resolutions
Posted: Wed Oct 09, 2013 8:33 am
by Germanunkol
I think the reason it's not working as you expect is this:
When you draw onto the canvas, the lg.scale(xscale,yscale) in res.lua (line 58) is active, plus your own scale function. Then, when you draw the canvas, YOUR scale function is inactive, but the res.lua's scale function is still active. This means that when using a canvas, the stuff you draw gets scaled by the res.lua's scaling function
twice, plus once by your own scaling function. Instead, each of the scaling functions should only scale it once, which can be achieved like so:
Move the canvas drawing stuff into function love.draw(), before calling res.render:
Code: Select all
function love.draw()
love.graphics.push()
love.graphics.setCanvas(canvas)
love.graphics.scale(5,3)
love.graphics.draw(image,0,0)
love.graphics.setCanvas()
love.graphics.pop()
res.render(draw)
end
Then, in the draw() function, only call the rendering of the canvas. This way, the stuff you draw doesn't get scaled twice by the res library:
Code: Select all
function draw()
love.graphics.draw(canvas)
end
Re: Canvas and multiple resolutions
Posted: Wed Oct 09, 2013 2:28 pm
by xCode195
Germanunkol wrote:-snip-
I LÖVE you man
That worked,thank you so much.
Re: [Solved]Canvas and multiple resolutions
Posted: Thu Oct 10, 2013 8:32 am
by Germanunkol
Glad I could help
Kudos goes to Micha though, he taught me how to do it...