View Full Version : calculating fps
06-07-2001, 09:59 PM
Hi, i'm calculating my fps with the function in time.h: time( ). But i can only get a difference of seconds for calculating fps. It seems like there should be some way to get time in at least milliseconds. Does anyone know how?
gettimeofday() on most BSD based systems (Linux included)
timeGetTime() (or something like that) on Win32
06-08-2001, 01:14 AM
If you are on Visual C try:
Gives time in milliseconds...
06-08-2001, 07:23 AM
For most accurate results checkout QueryPerformanceFrequency() and QueryPerformanceCounter() which give time in processor clocks as LARGE_INTEGER (64 bit) values.
06-10-2001, 04:06 AM
I use this for win32.
LARGE_INTEGER time, last_time, diff, frequency;
//Initialize the variables with this.
//Get the performance counter metrics.
//Set iniitial frame time to 0.
g_frame_time = 0.f;
//Then call this each frame, to setup the current frame time in g_frame_time.
last_time = time;
diff.QuadPart = time.QuadPart - last_time.QuadPart;
frame_time = (GLfloat)diff.QuadPart / (GLfloat)frequency.QuadPart;
g_frame_time = frame_time;
Then frame rate is simple 1.0f / g_frame_time.
Use g_frame_time for movements, to make stuff frame rate independant. For example to move something at 1 unit per second, do.
position += velocity * g_frame_time;
where velocity has magnitude of 1.
Or something like that.
[This message has been edited by Nutty (edited 06-10-2001).]
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.