counter - Winapi: GetTickCount() can't get ELAPSED TIME -


hi got simple fps counter in animation. fps counts fine don't know why can't measure animation time. normaly time glutget(glut elapsed time) since have go winapi (or must) use gettickcount() here code:

int frames=0; int currenttime=0; int previoustime=0; int intervaltime=0; int countertime=0; float fps;  void fpscount(){     frames++;     currenttime = gettickcount();     intervaltime = currenttime - previoustime;      if(intervaltime >= 1000)     {         fps = frames / (intervaltime / 1000.0f);         previoustime = currenttime;         frames = 0;         countertime += intervaltime;      } } 

i measure line: countertime += intervaltime; , strange values like: 44834406 44835420

if define line countertime = intervaltime+countertime; countertime gets values above.

if define line countertime = intervaltime; countertime gets values: 1014 1014 are not summed.

the correct values should be: 1014 2028 . . .

what i'am doing wrong?

try instead:

int frames = 0; dword previoustime = 0; float fps = 0.0f;  void fpscount() {     frames++;      dword currenttime = gettickcount();     dword intervaltime = (currenttime >= previoustime)         ? (currenttime - previoustime)         : ((maxdword - previoustime) + currenttime);      if (intervaltime >= 1000)     {         fps = frames / (intervaltime / 1000.0f);         previoustime = currenttime;         frames = 0;     } } 

and don't forget initialize previoustime current time when first start processing frames.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -