Page 1 of 4

TLfres - resolution freedom

Posted: Wed Apr 27, 2011 12:21 am
by Taehl
This is a little lib I extracted from a few of my recent projects. Its purpose is to allow a game to run in any resolution or aspect ratio, handling all the scaling, centering, and letterboxing (known issue: width must be >= height or letterboxing doesn't work). You can do some neat things with it, however, I've built it to be a fire-and-forget solution if you don't want to plumb its more advanced capabilities. Note: It handles different aspect ratios WITHOUT stretching.

How to use: Assuming you have a game built for a fixed-size window, this is all you need to do:
1) In love.load(), add the line TLfres.setScreen(). If you want to use a resolution other than the default 800x600, then you need to pass it a table of screen parameters - example: TLfres.setScreen({w=1600, h=900, full=true, aa=0}). Make sure you always use TLfres.setScreen INSTEAD of love.graphics.setMode.
2) At the top of love.draw, call TLfres.transform().
3) If you want letterboxing, at the end of love.draw, call TLfres.letterbox(). If you're not using the default 4:3 aspect ratio, you need to pass it the ratio - example: TLfres.letterbox(16, 9).

You should now be able to use any resolution with impunity. Full documentation, as usual, is on the wiki.

Download it here.

Re: TLfres - resolution freedom

Posted: Wed Apr 27, 2011 4:27 am
by Robin
Interesting. How about a version of setScreen that calls getMode rather than setMode, so we can use conf.lua to define the resolution?

Re: TLfres - resolution freedom

Posted: Wed Apr 27, 2011 4:32 am
by Taehl
Because then you'd need to use love.graphics.setMode and then call TLfres.setScreen (possibly needing to pass it some of the same information) right afterwards. Seems backwards to me. Since you should never change the resolution without letting TLfres rework its internals, it makes much more sense (at least, to me) to do it this way.

Re: TLfres - resolution freedom

Posted: Wed Apr 27, 2011 11:17 am
by Robin
Taehl wrote:Because then you'd need to use love.graphics.setMode and then call TLfres.setScreen (possibly needing to pass it some of the same information) right afterwards. Seems backwards to me. Since you should never change the resolution without letting TLfres rework its internals, it makes much more sense (at least, to me) to do it this way.
Except if you want to use love.conf(), which I prefer above setMode, as I said above.

Re: TLfres - resolution freedom

Posted: Wed Apr 27, 2011 2:04 pm
by bartbes
And is preferable because it doesn't create 2 windows.

Re: TLfres - resolution freedom

Posted: Wed Apr 27, 2011 2:15 pm
by Taehl
Fine. But you'll need to give Love a getMode function first ;P
Since you're too lazy to call just ONE function, I'll even make it do this automatically for you when you call TLfres.transform without having called TLfres.setScreen.

The download has been updated.

But for the record, just setting resolution in the conf.lua doesn't make any sense. If you set it there, then you aren't changing it ingame. If you aren't changing it ingame, you're building the game to that specific res. If you're building it to a specific res and don't change it, why in the world do you need a library to handle resolution changes?

Re: TLfres - resolution freedom

Posted: Wed Apr 27, 2011 3:04 pm
by Robin
Taehl wrote:But for the record, just setting resolution in the conf.lua doesn't make any sense. If you set it there, then you aren't changing it ingame. If you aren't changing it ingame, you're building the game to that specific res. If you're building it to a specific res and don't change it, why in the world do you need a library to handle resolution changes?
Not at all. It could be used for a default resolution. That is how I use it, actually.

And even if you don't let the player change the resolution, your library can still be useful. Hardcoding for specific resolutions is bad style. (And I know I have done it in the past and I am still doing it in some places, but it would be fair to give the option to people who are not as hypocritical as me. ;))

Re: TLfres - resolution freedom

Posted: Wed Apr 27, 2011 3:42 pm
by Taehl
You may be interested to hear, then, that while TLfres defaults to using an 800x600 "internal" res (to make it as easy as possible to fire-and-forget into the average game), TLfres.setScreen takes parameters that can change that - I, personally, like using a range of 1.0 being the width of the screen. You can also specify if the screen is meant to be top-left aligned (default, to suit Love) or centered (which I prefer).

Re: TLfres - resolution freedom

Posted: Wed Apr 27, 2011 5:20 pm
by Robin
I'm sorry, I don't see how that is relevant to my point.

Re: TLfres - resolution freedom

Posted: Wed Apr 27, 2011 5:45 pm
by Taehl
Because using TLfres, you specify your favorite range of numbers to represent space on the screen, instead of using fixed pixels. Thus, you're not hardcoding to a specific resolution. So you can code not in bad style.