How to Limit Framerate?

Not sure where to post this, but I am trying to limit my framerate because my videocard is making a sort-of “whining” noise when my FPS gets too high. The higher the FPS, the higher the pitch of the “whine”.



I looked around and everyone suggested I use the AppSettings.setFrameRate() method, but it does not seem to be limiting my FPS.



[java]

AppSettings newSettings = new AppSettings(true);

newSettings.setFrameRate(60);

setSettings(newSettings);

[/java]



And as you can see, the FPS is really high…



http://imgur.com/HWqc2

you could use vsync, or do an artifical sleep in the update(if the framerate is too high)



Btw, that noise is no reason to concern, its just the voltage converter stuff on the graficcard, that oscillates at around your framerate, giving hearable phantom frequencies. Of course its a waste of power, since the display wont show most of those frames anyway.

Have you called restart() to apply the changes to the settings?

@EmpirePhoenix said:
you could use vsync, or do an artifical sleep in the update(if the framerate is too high)

Btw, that noise is no reason to concern, its just the voltage converter stuff on the graficcard, that oscillates at around your framerate, giving hearable phantom frequencies. Of course its a waste of power, since the display wont show most of those frames anyway.


Thanks Empire. Setting vSync to true seems like a better solution than just limiting the framerate to an arbitrary number. I was just not aware I needed to call restart() to apply the changes. Thanks for the extra info also, it just made me a bit nervous hearing the whining sound and I was hoping it wasn't the gpu fan working overtime.

@Momoko_Fan said:
Have you called restart() to apply the changes to the settings?


Thanks Momoko. Seems odd that I would need to call restart() to apply the settings. I assumed setSettings(newSettings) would automatically apply.

I use setFrame(500) and it works fine. You must be doing something wrong.

are you using RC2? and have you tried doing a clean + build?



i remember @nehon saying something about the value being cached, can’t find the thread tho

@gwin003 said:
[java]
AppSettings newSettings = new AppSettings(true);
newSettings.setFrameRate(60);
setSettings(newSettings);
[/java]

Where do you do that? looks like you do that in the simpleInit or somewhere in the SimpleApplication code. Then you have to call restart because once you're there the application is already started.

if you want to apply that at start do it in your main() method just after the app has been instantiated.
[java]
public static void main(String[] argv){
MyApp app = new MyApp()
AppSettings newSettings = new AppSettings(true);
newSettings.setFrameRate(60);
app.setSettings(newSettings);
app.start();
}
[/java]
2 Likes

Thanks for all the quick replies. I got it working as of my last post, but I changed it using @nehon 's suggestion. Creating the settings before starting the app seems like the more efficient way of doing things.



[java]

public static void main(String[] args) {

HelloCollision app = new HelloCollision();

app.setSettings(createSettings());

app.start();

}



private static AppSettings createSettings()

{

AppSettings newSettings = new AppSettings(true);

newSettings.setFrameRate(60);

newSettings.setVSync(true);

newSettings.setTitle(“Window Title”);

return newSettings;

}

[/java]



Just curious, but is there any advantage to calling setVSync(true) while also calling setFrameRate(60)? I would think not, but I’m still learning.



Edit: And yes, I was originally calling that code at the beginning of simpleInitApp().

1 Like
@gwin003 said:
Just curious, but is there any advantage to calling setVSync(true) while also calling setFrameRate(60)? I would think not, but I'm still learning.


Suppose your monitor's refresh rate is 120Hz. If you lock max fps at 60 you would effectively lock it lower than the optimal refresh speed for your monitor.

Although I'm wondering if vsync would override this. Might be interesting to verify that.

What I'd suggest you is to use a relatively high FPS and stick with that. Higher than 1000 is useless but locking it down at 60 is rather aggravating for those that have really good hardware. As I said, I use 500 FPS as a baseline. That way I see how things evolve as I add stuff. And no, at 500 the capacitors are not screaming. ;)

depends, I would still rather not subject my GPU to more work than it needs. I always use VSync, unless i wanna test how high my FPS can get, and its > 5000 :slight_smile:



http://www.dailytech.com/Hot+Starcraft+II+is+Frying+Graphics+Cards+Blizzard+Issues+Temporary+Fix/article19224.htm

Uusually displays use 60hz so vsync equals 60 hz, but makes sure that no frame is changed while it is being drawn → google tearing artifacts

However ther are displays that can render 120hz (many crt, and a few modern 3d capable monitors/tv’s)

Also if a tv is used you might render 50hz or 42hz instead with vsync.

@madjack said:
Suppose your monitor's refresh rate is 120Hz. If you lock max fps at 60 you would effectively lock it lower than the optimal refresh speed for your monitor.

Although I'm wondering if vsync would override this. Might be interesting to verify that.


For anyone that is interested, setFrameRate(500) and setVSync(true) caps the frame rate at 60, so vSync overrides the setFrameRate.
But when setFrameRate(20) and setVSync(true) are both called, framerate caps out at 20. So whichever one is lowest gets used.

What I'd suggest you is to use a relatively high FPS and stick with that. Higher than 1000 is useless but locking it down at 60 is rather aggravating for those that have really good hardware. As I said, I use 500 FPS as a baseline. That way I see how things evolve as I add stuff. And no, at 500 the capacitors are not screaming. ;)


Good idea, when I start working on my actual project I will probable use this method. Thanks for the help everyone!
2 Likes
@gwin003 said:
For anyone that is interested, setFrameRate(500) and setVSync(true) caps the frame rate at 60, so vSync overrides the setFrameRate.
But when setFrameRate(20) and setVSync(true) are both called, framerate caps out at 20. So whichever one is lowest gets used.

Good to know.

Thanks for that.

Whatever you choose do everyone a favor leave it optional for people to use vsync or not. There nothing else I hate more than a developer telling me what my game's settings should be and how I should play my games. Please don't be that arsehole. ;)
@madjack said:
There nothing else I hate more than a developer telling me what my game's settings should be and how I should play my games.


hope your listening devs, new way to annoy madjack.

Remove setframerate and make vsync compulsory :)
@wezrule said:
Remove setframerate and make vsync compulsory :)


I'll hack your sources. :P

Some people may have vsync disabled completely in control panel, in that case, setting vsync does nothing.