Limit on frame-rate?

I’ve programmed a simple 3D engine with opengl but when I move in my 3D world with the engine I move extremely fast becouse the framerate is very high. Does anybody know how I can set a limit on the framerate? I know there is a funtion for limit the framerate and color-bits but I can’t found it, can anybody help me?

Many thanks for your interest!

Maurits Lawende

Well, actually, you have to look at problem from the other end.

You want your 3D engine to run as fast as possible..

You don’t limit the framerate, instead you limit the speed of
your objects.

But then I had to know ingame what the FPs is so I can adjust the object and walking speed.

That’s right.

You have to give all objects their own frame rate.

Let the game engine run as fast as it can.

Apparently you’ve tied all your game’s activies to your refresh rate. This isn’t a good idea as the refresh rate will differ on different computers with different graphics cards. I would suggest you use some thing else. When I use MFC on windows, refresh is handled in the CWinApp::OnIdle() function. I use the multimedia timer to tell when refresh is due and refresh the screen then. Likewise I use OnIdle and the multimedia timer to control other game activity so that it will run the same on all machines. I think GLUT has a glutTimer function. The GLUT experts could say more to that.

windows timers are too slow, the window messages arive at around 25 time a second. what you want to do is make a call to ‘GetTickCount()’ this gives you the number of milliseconds that windows has been up. all you have to do is keep the last value an compare to the current if the time you specify has elapsed, then update you objects, but you can still render every loop. this will give you a high frame rate, but a constant update to your objects…

Originally posted by john_at_kbs_is:
windows timers are too slow, the window messages arive at around 25 time a second. what you want to do is make a call to ‘GetTickCount()’ this gives you the number of milliseconds that windows has been up. all you have to do is keep the last value an compare to the current if the time you specify has elapsed, then update you objects, but you can still render every loop. this will give you a high frame rate, but a constant update to your objects…

Hi,

I’m also interested in doing this. Can you elaborate a little more on this topic? If the elapsed time has not passed, do you wait? or ignore updating of the objects and go to the next frame? Thanks.

Frederico Jeronimo

One hint: don’t use GetTickCount(), it has very very bad resolution (55 ms on win9x/me systems), use either timeGetTime() which is 1 ms resolution or, even better, QueryPerformanceCounter() and QueryPerformanceFrequency(), which gives you very good resolution.

-Lev

[This message has been edited by Lev (edited 01-21-2002).]

timeGetTime() is the multimedia timer. I find it works fine for me. QueryPerformance*() is supposed to be even better but I read somewhere that in the long run it slows down your program because it calls or queries something too often. QueryPerformance*() should be good for movies and sound cause they are high frequency. However, if you only need to update an object 33 times a second timeGetTime() is more than enough for the job.

In terms of use, everytime OnIdle() is called check if the activity is due. If so do it, otherwise ignore it and move on. Alternatively you can check how much time has passed between frames and update the time intervals you use to move your objects. That way it will still run right and be really smooth on high end systems.

I agree, if you only have 33 fps, timeGetTime() is sufficient, but in games you often have 100 to 200 and more fps, there timeGetTime() will not perform as good as QueryPerformance*.

-Lev

I was under the impression Furrage meant the windows message timer created with SetTimer.

The QueryPerformanceCounter sounds a lot better, but what’s with this: (from MSDN) ‘The QueryPerformanceCounter function retrieves the current value of the high-resolution performance counter, if one exists.’, if one exists? How often can this happen?

John.

You can safely assume that all PCs have one (unless your target system is <i286)

cool, thanks…