Sign in to follow this  
3Dgonewild

Lock FPS?

Recommended Posts

So far i've been using lazyfoo's fps limit class for my sdl apps. What im asking for , is , a way to lock fps that will work with opengl(opengl+sdl)...any help?

Share this post


Link to post
Share on other sites
I don't see why it wouldn't work with OpenGL and/or SDL.
All it does is to wait if the frames exceed a certain limit.
 //If we want to cap the frame rate
if( cap == true )
{
//While the frame time is not up
while( fps.get_ticks() < 1000 / FRAMES_PER_SECOND )
{
//wait...
}
}
What wasn't that didn't work when you tried it?

Share this post


Link to post
Share on other sites
Quote:
Original post by blueapple
I don't see why it wouldn't work with OpenGL and/or SDL.
All it does is to wait if the frames exceed a certain limit.
 //If we want to cap the frame rate
if( cap == true )
{
//While the frame time is not up
while( fps.get_ticks() < 1000 / FRAMES_PER_SECOND )
{
//wait...
}
}
What wasn't that didn't work when you tried it?


I tried it few minutes after i created this thread , and its working...Anyway , is there any other safer/faster way to draw frames?

Share this post


Link to post
Share on other sites
Quote:
Original post by 3Dgonewild
Quote:
Original post by blueapple
I don't see why it wouldn't work with OpenGL and/or SDL.
All it does is to wait if the frames exceed a certain limit.
 //If we want to cap the frame rate
if( cap == true )
{
//While the frame time is not up
while( fps.get_ticks() < 1000 / FRAMES_PER_SECOND )
{
//wait...
}
}
What wasn't that didn't work when you tried it?


I tried it few minutes after i created this thread , and its working...Anyway , is there any other safer/faster way to draw frames?


Well there is nothing unsafe about the way you are doing it. As far as faster goes, I think this works just fine too, as long as you are achieving the fps you are looking for.

Share this post


Link to post
Share on other sites
Quote:
Original post by bschneid
Quote:
Original post by 3Dgonewild
Quote:
Original post by blueapple
I don't see why it wouldn't work with OpenGL and/or SDL.
All it does is to wait if the frames exceed a certain limit.
 //If we want to cap the frame rate
if( cap == true )
{
//While the frame time is not up
while( fps.get_ticks() < 1000 / FRAMES_PER_SECOND )
{
//wait...
}
}
What wasn't that didn't work when you tried it?


I tried it few minutes after i created this thread , and its working...Anyway , is there any other safer/faster way to draw frames?


Well there is nothing unsafe about the way you are doing it. As far as faster goes, I think this works just fine too, as long as you are achieving the fps you are looking for.

Hmm , ok i got it :) !

By the way , why he divides the two values?
FRAMES_PER_SEC=60
1000/FRAMES_PER_SEC = 17 fps

This :
while(fps.get_ticks()<17)
wont work ?

Share this post


Link to post
Share on other sites
Well what you have works too (I'm assuming the math was right) but here's the deal: The #define FRAMES_PER_SECOND code defines FRAMES_PER_SECOND to be some number. If you use 1000/FRAMES_PER_SECOND then if you decide to change your fps you just have to change the #define FRAMES_PER_SECOND part to a different number, then re-compile. If you just put a number there, then if you want to change it you will have to re-calculate and replace that number in all of your code instead of just changing a #define. It might not be a hassle for your purposes, but in many cases doing it the second way could mean searching through a lot of code.

Share this post


Link to post
Share on other sites
Quote:
Original post by bschneid
Well what you have works too (I'm assuming the math was right) but here's the deal: The #define FRAMES_PER_SECOND code defines FRAMES_PER_SECOND to be some number. If you use 1000/FRAMES_PER_SECOND then if you decide to change your fps you just have to change the #define FRAMES_PER_SECOND part to a different number, then re-compile. If you just put a number there, then if you want to change it you will have to re-calculate and replace that number in all of your code instead of just changing a #define. It might not be a hassle for your purposes, but in many cases doing it the second way could mean searching through a lot of code.


..hmm...then i could simply do this ?


#define CUSTOM_FPS_LIMIT 15

while (ticks<15)
{
//ooOoOpSSS!! WAIT1!#
}



.......anyway , i got my answer T_T!!

Share this post


Link to post
Share on other sites
I'll see if I can't explain this a little better this time. Your code would work, but you never actually use the value defined by CUSTOM_FPS_LIMIT. You might as well just delete that line because it is not being used.

Now check out this code:

#define FPS_LIMIT 20

if(ticks < 1000/FPS_LIMIT)
{
//wait
}



What the compiler does is recognizes FPS_LIMIT throughout your code to equal 20, since that is what it is '#define'd as. So when you compile the compiler replaces FPS_LIMIT with the number 20 all throughout your code.

If at any time I need to change the FPS_LIMIT, all I need to do is change '#define FPS_LIMIT 20' to '#define FPS_LIMIT x' where x is whatever number I want to make my new fps. But then I don't need to worry about changing the if statement, because when I compile the compiler will replace FPS_LIMIT in the if statement with my new value. It will do this everywhere I've typed FPS_LIMIT. I think your problem is simply not understanding how defines work. After reading that, I wasn't much clearer. Try googling.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this