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.
TLfres - resolution freedom
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
TLfres - resolution freedom
Last edited by Taehl on Sun Oct 16, 2011 8:33 pm, edited 1 time in total.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: TLfres - resolution freedom
Interesting. How about a version of setScreen that calls getMode rather than setMode, so we can use conf.lua to define the resolution?
Help us help you: attach a .love.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: TLfres - resolution freedom
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.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: TLfres - resolution freedom
Except if you want to use love.conf(), which I prefer above setMode, as I said above.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.
Help us help you: attach a .love.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: TLfres - resolution freedom
And is preferable because it doesn't create 2 windows.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: TLfres - resolution freedom
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?
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?
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: TLfres - resolution freedom
Not at all. It could be used for a default resolution. That is how I use it, actually.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?
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. )
Help us help you: attach a .love.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: TLfres - resolution freedom
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).
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: TLfres - resolution freedom
I'm sorry, I don't see how that is relevant to my point.
Help us help you: attach a .love.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: TLfres - resolution freedom
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.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Who is online
Users browsing this forum: Ahrefs [Bot] and 1 guest