Jump to content
  • Advertisement
Sign in to follow this  
farofeiro

Limit frame rate to 60 fps on Linux

This topic is 3733 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How can I limit the frame rate? I've searched a lot on internet but couldn't find any way to implement this. I did find how to show the frame rate, but nothing related to limit it. I also would like to have vertical sync activated (I'm not using SDL cause I'm already using QT), but couldn't find any good info for a Linux user.

Share this post


Link to post
Share on other sites
Advertisement
I'm surprised you didn't find anything, this is a common problem many people face and there are many ways to face this. Here is just one good link from gamedev I found similar to yours:
http://www.gamedev.net/community/forums/topic.asp?topic_id=499665&whichpage=1�

Share this post


Link to post
Share on other sites
What i found worked well was not limiting the frames drawn, let it draw as fast as possible, but only update the information only 60 times a second.
So you set up a timer that will call say,
UpdateInformation(); every 1/60th of a second, but just let your program draw as fast as possible. That way even though you are drawing at like maybe 200fps, information is only updating at the right pace.

Share this post


Link to post
Share on other sites
Quote:
Original post by Deftoned
What i found worked well was not limiting the frames drawn, let it draw as fast as possible, but only update the information only 60 times a second.
So you set up a timer that will call say,
UpdateInformation(); every 1/60th of a second, but just let your program draw as fast as possible. That way even though you are drawing at like maybe 200fps, information is only updating at the right pace.


Would it be better by setting up two threads, one for logic and the other for graphics where the graphics thread draw with vsync enabled?

Share this post


Link to post
Share on other sites
Last time I checked there was no (at least not an easy one) way to enable/disable vsinc from your app. That kind of functionality should be implemented in the xorg library or wrapped by SDL, but it isn't. In fact, there is no way to chose the refresh rate of a given resolution. If you set 640x480 with SDL it will default to 60hz no matter if your monitor can do 120hz.

To limit your framerate just flip the buffers once every 1/60 of a second.

if ((current_millisecs - last_milisecs_drawn) >= 1000/60)
DrawStuff();

all your logic calculations should always be done before that period of time or your framerate will drop.

I would personally make all graphics time-based, so no matter what's the speed of the computer or the refresh, the graphics will be always updated timely.

Share this post


Link to post
Share on other sites
Quote:
Original post by ma_hty
Quote:
Original post by Deftoned
What i found worked well was not limiting the frames drawn, let it draw as fast as possible, but only update the information only 60 times a second.
So you set up a timer that will call say,
UpdateInformation(); every 1/60th of a second, but just let your program draw as fast as possible. That way even though you are drawing at like maybe 200fps, information is only updating at the right pace.


Would it be better by setting up two threads, one for logic and the other for graphics where the graphics thread draw with vsync enabled?


Questions about multithreading frequently appear in the Game Programming forum, so try and have a look there. But otherwise, you can PM me, and I will tell you about the 2 common methods (you are partly describing one of them), so that we will not steal focus from the actual topic of this thread.

Share this post


Link to post
Share on other sites
Quote:
Original post by owl
Last time I checked there was no (at least not an easy one) way to enable/disable vsinc from your app. That kind of functionality should be implemented in the xorg library or wrapped by SDL, but it isn't. In fact, there is no way to chose the refresh rate of a given resolution. If you set 640x480 with SDL it will default to 60hz no matter if your monitor can do 120hz.

It is easy if you use the xrandr libs and glx directly. I'm quite sure that SDL exposes this functionality.

Share this post


Link to post
Share on other sites
Quote:
Original post by Fiddler
Quote:
Original post by owl
Last time I checked there was no (at least not an easy one) way to enable/disable vsinc from your app. That kind of functionality should be implemented in the xorg library or wrapped by SDL, but it isn't. In fact, there is no way to chose the refresh rate of a given resolution. If you set 640x480 with SDL it will default to 60hz no matter if your monitor can do 120hz.

It is easy if you use the xrandr libs and glx directly. I'm quite sure that SDL exposes this functionality.


Where can I find this xrandr lib. owl?

Share this post


Link to post
Share on other sites
Quote:
Original post by Fiddler
It is easy if you use the xrandr libs and glx directly. I'm quite sure that SDL exposes this functionality.
if you are using SDL, you can enable vsync by calling SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1), but I wont guarantee it works on all linux systems.

Share this post


Link to post
Share on other sites
If you aren't using SDL or some other wrapper library, you have to use one of the GLX extensions GLX_SGI_swap_control or GLX_MESA_swap_control.

It also obviously depends on your driver and the driver settings, which you can configure using DriConf (your distro should have a package). You can override those settings using environment variables, vblank_mode in the case of vblank settings.

Side note: The thread title is misleading, since we're talking about syncing to vblank, which may be at something else than 60Hz. If you really want to limit yourself to 60fps, you should just use an appropriate sleeping primitive (e.g. call to select).

Edit: Obviously, DriConf only works with the open source drivers. I'd expect the proprietary drivers have their own configuration tools.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!