View Full Version : calculating fps
grady
06-07-2001, 08: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
mcbastian
06-08-2001, 12:14 AM
If you are on Visual C try:
GetTickCount();
:-)
Gives time in milliseconds...
Greetings,
Sebastian
Relic
06-08-2001, 06:23 AM
For most accurate results checkout QueryPerformanceFrequency() and QueryPerformanceCounter() which give time in processor clocks as LARGE_INTEGER (64 bit) values.
Nutty
06-10-2001, 03:06 AM
I use this for win32.
//Globals.
LARGE_INTEGER time, last_time, diff, frequency;
GLfloat g_frame_time;
//Initialize the variables with this.
//Get the performance counter metrics.
QueryPerformanceCounter(&last_time);
QueryPerformanceCounter(&time);
QueryPerformanceFrequency(&frequency);
//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.
void CalcFrameTime(void)
{
GLfloat frame_time;
last_time = time;
QueryPerformanceCounter(&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.
[/CODE]
position += velocity * g_frame_time;
[/CODE]
where velocity has magnitude of 1.
Or something like that.
Nutty
[This message has been edited by Nutty (edited 06-10-2001).]
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.