🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Framrate

Started by
3 comments, last by Khorn 24 years, 1 month ago
How can I measure my framerate? I''ve tried to check the clock when i start to display and take the time when swapbuffer is done. But the problem is that this won''t get med exactly one sec. I can only count frames when it''ve produced more that one sec. F ex. 9 frames a'' 0.12 will give 1.08 sec and 8 will give 0.96... There must be an algoritm that can give me the accurate frames/sec. Or is it me that is just so tired right now?? (I hate early mornings) Thnx.
Me....!? What more can I say?
Advertisement
I do it like this:

void CTimer::Frame(){  m_fDeltaTime = GetTime() - m_fFrameTime;  m_fFrameTime += m_fDeltaTime;  // Update frames per second counter  m_dwNumFrames++;  if( m_fFrameTime - m_fLastUpdate > FPS_INTERVAL )  {    m_fFps = m_dwNumFrames / (m_fFrameTime - m_fLastUpdate);    m_dwNumFrames = 0;    m_fLastUpdate = m_fFrameTime;  }}




- WitchLord

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

For accurate timing check \link{http://glvelocity.demonews.com/files/timersource.zip}!

#define FPS_INTERVAL 50

DWORD timePrev. timeFPS;
WORD FPS, FPSCounter;
float timeElapsed;

void InitTimer()
{
FPSCounter = FPS = 0;
timePrev = timeFPS = timeGetTime();
}

/*
La seguente funzione deve essere richiamata AD OGNI CICLO
di rendering per il corretto calcolo degli FPS
*/
void TickTimer()
{
timeElapsed = (timeGetTime() - timePrev) / 1000.0f;
timePrev = timeGetTime();
if(FPSCounter == FPS_INTERVAL)
{
FPS = (WORD)((FRAME_INTERVAL * 1000) / (timePrev - timeFPS));
FPSCounter = 0;
}
else
FPSCounter++;
}

Call InitTimer at the beginning of the App and TickTimer al the beginning of EVERY rendering function (DrawGLScene in Nehe''s tutorials).

Doing that you''ll have a var called FPS that is updated every FPS_INTERVAL call to DrawGLScene and that is the effective frame per second of your rendering scene. Then you have also a var called timeElapsed that is the time elapsed (expressed in seconds) from a call to DraGLScene and another. This is useful for update objects and camera movements depending on the speed of the computer so that your scene can moves at the same speed in different systems.

I''m using the GetTickCount Win32 function.

This topic is closed to new replies.

Advertisement