love.graphics.getModes

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
User avatar
Spec0pAssassin
Prole
Posts: 8
Joined: Sun Jul 01, 2012 6:47 pm
Location: My head, USA

love.graphics.getModes

Post by Spec0pAssassin »

Word of warning I'm rather new at this.

So what I want to do is just create a simple menu that includes a way to change your windows resolution by presenting a list of them to choose from but I don't quite understand how to use "love.graphics.getModes" and whatever other methods I need incorporate to achieve this. I've looked what I believe is a good example that uses "love.graphics.getModes" but it involved using kikito's middleclass library, and I haven't quite learned how to use or understand how peoples libraries work (oop? not there yet). I'd like to figure it out this way, if that can be explained, but am also curious if there are alternative ways to do this.

I'm rather new to programming and lua so I just can't understand it on my own and need some loving help. :crazy:
-Spec0pAssassin
Wait. What?
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: love.graphics.getModes

Post by Lafolie »

You can use love.graphics.checkMode to do this.

Code: Select all

ratios = {800 / 600, 1440 / 900, 1960 / 1080}
supported = {fullscreen = {}}
for scale = 1, 6 do
	for k, ratio in ipairs(ratios) do
		local x = 320 * scale
		local y = x * ratio
		local key = tostring(x .. "x" .. y)
		local res = {width = x, height = y}
		if love.graphics.checkMode(x, y) then
			supported[key] = res
		end
		if love.graphics.checkMode(x, y, true) then
			supported.fullscreen[key] = res
		end
	end
end
--check for rogue resolution
local key = "1680x1050"
local res = {width = 1680, height = 1050}
if love.graphics.checkMode(1680, 1050) then
	supported[key] = res
end
if love.graphics.checkMode(1680, 1050, true) then
	supported.fullscreen[key] = res
end
Haven't tested this, but it should work.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
User avatar
Spec0pAssassin
Prole
Posts: 8
Joined: Sun Jul 01, 2012 6:47 pm
Location: My head, USA

Re: love.graphics.getModes

Post by Spec0pAssassin »

If it's not to much trouble do you think you can comment that out for me?(like explain whats doing what) Some of what your code is doing is a little beyond me so implementing it into something testable will take sometime on my end. What's the difference between checkModes and getModes?
-Spec0pAssassin
Wait. What?
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: love.graphics.getModes

Post by Lafolie »

I linked to love.graphics.checkMode wiki page.

The script is pretty straightforward. It generates resolutions according to three popular aspect ratios and performs two test for each resolution: windowed and fullscreen. If supported, the resolution is added to a table. How the results are stored doesn't really matter, but I stored them here in the following fashion, using some simple tables:

Let our resolution be 800 x 600 -

supported["800x600"] = {width = 800, height = 600}
supported.fullscreen["800x600"] = {width = 800, height = 600}

This data format allows you to easily access the table to display the available options to the player and also to switch the resolution.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
User avatar
slime
Solid Snayke
Posts: 3160
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: love.graphics.getModes

Post by slime »

Lafolie wrote:I linked to love.graphics.checkMode wiki page.

The script is pretty straightforward. It generates resolutions according to three popular aspect ratios and performs two test for each resolution: windowed and fullscreen. If supported, the resolution is added to a table. How the results are stored doesn't really matter, but I stored them here in the following fashion, using some simple tables:

Let our resolution be 800 x 600 -

supported["800x600"] = {width = 800, height = 600}
supported.fullscreen["800x600"] = {width = 800, height = 600}

This data format allows you to easily access the table to display the available options to the player and also to switch the resolution.
How is that better than using love.graphics.getModes to get a list of all supported fullscreen resolutions? (all windowed mode width/height combinations will probably work as long as they aren't bigger than the desktop resolution).
User avatar
Spec0pAssassin
Prole
Posts: 8
Joined: Sun Jul 01, 2012 6:47 pm
Location: My head, USA

Re: love.graphics.getModes

Post by Spec0pAssassin »

So however I decide to create said table of resolutions, I assume printing them to the window would require converting the items within the table into strings? I feel like there's an alternative to that aswell, what would that be if there is one? Or am I thinking of doing that wrong?
Last edited by Spec0pAssassin on Thu Mar 21, 2013 9:32 am, edited 1 time in total.
-Spec0pAssassin
Wait. What?
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: love.graphics.getModes

Post by Lafolie »

slime wrote: How is that better than using love.graphics.getModes to get a list of all supported fullscreen resolutions? (all windowed mode width/height combinations will probably work as long as they aren't bigger than the desktop resolution).
I did not know that function existed! Please ignore everything I said, once again.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 5 guests