How to set Refresh Rate?

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
UnixRoot
Citizen
Posts: 80
Joined: Mon Nov 08, 2021 8:10 am

How to set Refresh Rate?

Post by UnixRoot »

Hello.

Love2D offers 2 different full screen modes. The desktop fullscreen mode uses the resolution and refresh rate of the Desktop.

But I would like to use the exclusive fullscreen mode.

How can I set the refresh rate in Love2D in exclusive mode? I tested my game on an older CRT monitor capable of 160 Hz and on a modern 4K TV, that is capable of 120 Hz in Full HD. On both, 60 Hz was automatically selected, even though much higher refresh rates are available.

Somehow the exclusive fullscreen mode doesn't make sense if you can't set the refresh rate. In every older game with exclusive fullscreen mode, you could set the resolution, color depht and refesh rate.
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: How to set Refresh Rate?

Post by darkfrei »

Not sure, but it looks like that you need to change the love.run function
https://love2d.org/wiki/love.run
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
UnixRoot
Citizen
Posts: 80
Joined: Mon Nov 08, 2021 8:10 am

Re: How to set Refresh Rate?

Post by UnixRoot »

darkfrei wrote: Sat Nov 13, 2021 9:51 am Not sure, but it looks like that you need to change the love.run function
https://love2d.org/wiki/love.run
Thanks for your answer, but I don't want to change the game speed / FPS, ticks etc, I want my game to run at a set resolution and screen refresh rate (Hz) in exclusive fullscreen mode.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to set Refresh Rate?

Post by pgimeno »

Hm, for me I can select a refresh rate of 60 or 75 with xrandr, and it affects the whole desktop, it's not just a fullscreen thing. So it's probably OS specific. Apparently SDL supports changing the refresh rate: https://wiki.libsdl.org/SDL_DisplayMode mentions a refresh rate field, but this functionality is not exposed to Löve. I guess that's material for a feature request.
User avatar
UnixRoot
Citizen
Posts: 80
Joined: Mon Nov 08, 2021 8:10 am

Re: How to set Refresh Rate?

Post by UnixRoot »

Thanks for your answer. Then I don't understand the point of the "exclusive" fullscreen mode in Love2D.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: How to set Refresh Rate?

Post by grump »

UnixRoot wrote: Sat Nov 13, 2021 12:09 pm Thanks for your answer. Then I don't understand the point of the "exclusive" fullscreen mode in Love2D.
"desktop" creates a screen-sized borderless window and doesn't change the video mode. "exclusive" allows you to change the video mode and use different resolutions.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to set Refresh Rate?

Post by pgimeno »

Take into account that Löve versions before 0.9 used SDL 1, which to my knowledge doesn't support different refresh rates. Apparently no one before you has asked about that feature.

I've checked and indeed, in my system this LuaJIT program shows the 75 Hz modes:

Code: Select all

local ffi = require'ffi'
local sdl = ffi.load'libSDL2.so'
assert(sdl)
ffi.cdef[[
  int SDL_Init(uint32_t flags);
  int SDL_GetNumDisplayModes(int disp);
  typedef struct {
    uint32_t format;
    int w;
    int h;
    int refresh_rate;
    void *driverdata;
  } SDL_DisplayMode;
  int SDL_GetDisplayMode(int disp, int modenum, SDL_DisplayMode *mode);
  void SDL_Quit(void);
]]
assert(sdl.SDL_GetDisplayMode)
local z = ffi.new[[ SDL_DisplayMode[1] ]]
z[0].format = 0
z[0].w = 0
z[0].h = 0
z[0].refresh_rate = 0
z[0].driverdata = nil

local SDL_INIT_VIDEO = 0x20
if not love then sdl.SDL_Init(SDL_INIT_VIDEO) end

local nModes = sdl.SDL_GetNumDisplayModes(0)
for i = 0, nModes - 1 do
  local R = sdl.SDL_GetDisplayMode(0, i, z)
  print(z[0].w, z[0].h, z[0].refresh_rate)
end
if love then
  return love.event.quit()
else
  sdl.SDL_Quit()
end
(for Windows you may need to change .so to .dll, and for Mac to .dylib or something).

Output in my system:

Code: Select all

1280	1024	75
1280	1024	60
1152	864	75
1024	768	75
1024	768	70
1024	768	60
800	600	75
800	600	72
800	600	60
800	600	56
640	480	75
640	480	73
640	480	60
I haven't tried to actually change it, but that shows that SDL2 does support it, therefore it should be possible.

Edit: I've tried using Löve to change to exclusive fullscreen mode and print the FPS. As you can see in the list above, the only available frequency in my monitor for 1152x864 is 75 Hz. If I set the 1152x864 mode, indeed the display rate is 75 Hz, but if I request any other, Löve apparently falls back to 60 Hz (the default for the desktop). If I change my desktop to a 75 Hz mode, Löve only selects 75 Hz modes in fullscreen. So yes, I think there's solid ground for a feature request to change the refresh rate.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: How to set Refresh Rate?

Post by grump »

pgimeno wrote: Sat Nov 13, 2021 3:09 pm (for Windows you may need to change .so to .dll, and for Mac to .dylib or something).
Just ffi.load('SDL2') should be enough and work on every system. prefix and extension are added by LuaJIT.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 44 guests