Is there a way to get the current monitor resolution?

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
O/m
Prole
Posts: 4
Joined: Fri May 18, 2012 3:46 pm

Is there a way to get the current monitor resolution?

Post by O/m »

I want to be able to change to fullscreen mode while not defaulting to some random resolution.
More specificly, I don't want the screen to change resolution when I switch to fullscreen.
So if I'm using this,

Code: Select all

local w, h, fullscreen, v, f = love.graphics.getMode()
love.graphics.setMode(x, y, true, v, f)
to go fullscreen. I need to know what is the current resolution to set x and y.
Last edited by O/m on Sat Feb 23, 2013 5:53 pm, edited 1 time in total.
Automatik
Citizen
Posts: 57
Joined: Sun Feb 17, 2013 7:05 pm

Re: Is there a way to get the current monitor resolution?

Post by Automatik »

You can use:

Code: Select all

love.graphics.setMode(0, 0, true, v, f)
Then, it will default to the current resolution.
Also, if it do a black screen for you, use:

Code: Select all

love.graphics.setMode(0, 0, true, v, f)
love.graphics.setMode(love.graphics.getWidth(),love.graphics.getHeight(), true, v, f)
O/m
Prole
Posts: 4
Joined: Fri May 18, 2012 3:46 pm

Re: Is there a way to get the current monitor resolution?

Post by O/m »

yep, it works like you said.
can you explain why we need the second line there?
it would be better not to have to set the mode twice.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Is there a way to get the current monitor resolution?

Post by Boolsheet »

O/m wrote:can you explain why we need the second line there?
it would be better not to have to set the mode twice.
It's a bug in LÖVE 0.8.0. The OpenGL viewport doesn't get set properly if the zeros are used. It will be fixed in the next version.
Shallow indentations.
O/m
Prole
Posts: 4
Joined: Fri May 18, 2012 3:46 pm

Re: Is there a way to get the current monitor resolution?

Post by O/m »

OK, thanks for the help!
User avatar
Daniel Eakins
Citizen
Posts: 99
Joined: Thu Jul 18, 2013 9:14 pm
Location: France

Re: Is there a way to get the current monitor resolution?

Post by Daniel Eakins »

Is there a way to get the current monitor resolution without visibly changing the window size? (For example, if my game window is 320x200 and I want to get the monitor resolution, the code above will visibly change the window size.)
User avatar
slime
Solid Snayke
Posts: 3166
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Is there a way to get the current monitor resolution?

Post by slime »

In 0.9.0 you can use [wiki]love.window.getDesktopDimensions[/wiki].

The current resolution will also often be the largest width and height in the table returned by [wiki]love.graphics.getModes[/wiki] ([wiki]love.window.getFullscreenModes[/wiki] in 0.9.0), although it likely will not be the case if the user is in OS X with a retina display.
User avatar
Daniel Eakins
Citizen
Posts: 99
Joined: Thu Jul 18, 2013 9:14 pm
Location: France

Re: Is there a way to get the current monitor resolution?

Post by Daniel Eakins »

Thanks! I'll check this out :D
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 6 guests