# Problem: Too fast FPS in demo's from tutorials

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

## Recommended Posts

It was hard to fiind a subject to describe my problem properly. Anyways, my problem is that when I run the examples you get in the tutorials they tend to run extremely fast, that is so fast that it's beyond 999fps. Is there anyway to solve this? I'm now on lesson 11 and the waves on the texture are so fast that it's damn ugly to look at.

##### Share on other sites
mesure the time it took to render the last frame (lets call it delta), then sleep for 1 / FRAME_RATE - delta.

Note that you need both sleep and time quering functions with good precisission for this to work (getimeofday, usleep on Unix systems).

alternatively you can calculate when the next frame should be drawn and add an idle loop at the end of you rendering code that does nothing as long as the current time is less than what you calculated for the next frame.

##### Share on other sites
Thx... I solved the problem, I made a simple function using the time.h header.
It doesn't contain any calculation of current framerate, all it does is run a loop for a given number of milliseconds, the given number is of your choosing. It works fine in theese simple turtorials at least. You just guess your way to a fitting number, to obtain the framerate you want.

void SlowdownFPS(int fps){		clock_t endwait;	int waitMs = 1000/fps;	endwait = clock() + utvid;	while (clock() < endwait) {}}

##### Share on other sites
Oh, by FRAME_RATE I meant the limit you want to set for the framerate. For more complicated sceens (or if you target a wide array of hardware) it makes sence to take the time that the last frame took to render into account. Calculating the delta ist equivalent to 2 cals to clock and a substraction. So it isn't that much of an overhead.

busy wait is considered ok for games, but I still prefere sleep. Its nice if some long running process that runs in the backround still gets the uneeded processor time.

##### Share on other sites
Quote:
 Original post by Mapster87Thx... I solved the problem, I made a simple function using the time.h header.It doesn't contain any calculation of current framerate, all it does is run a loop for a given number of milliseconds, the given number is of your choosing. It works fine in theese simple turtorials at least. You just guess your way to a fitting number, to obtain the framerate you want.void SlowdownFPS(int fps){ clock_t endwait; int waitMs = 1000/fps; endwait = clock() + utvid; while (clock() < endwait) {}}

For demo's/tutorials your solution is good enough. For games this would be a waste, as you are just throwing your cpu-cycles away. Most games use time-based animations, try searching for it on the forums.

##### Share on other sites
Just force vsync on your graphics drivers.

If you need help doing this, do you have ATI or NVIDIA?

##### Share on other sites
I don't have much experience in programming and I ran into a problem with measuring the time it took to render the last frame. I don't know how to convert the clock_t form to an int.

Anyways, I know it isn't good enough for a game, but at the moment I don't know a percent of what I need to make a game, though that's my goal.

edit:
Ahh.. that was another solution. worked fine that too Boder.

[Edited by - mapster on April 18, 2006 1:17:27 PM]

##### Share on other sites
VSync will be better for you, the method you were using works fine, but won't behave well on different hardware (or even on your own hardware if other tasks are taking up system resources as well).

##### Share on other sites
This sleep function you speak of nefthy, where do I find information about it?

##### Share on other sites
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/sleep.asp

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633759
• Total Posts
3013715
×