Jump to content

  • Log In with Google      Sign In   
  • Create Account


FPS Counter


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 Taphreek   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 March 2001 - 02:46 PM

I didn''t know whether this is considered graphics, or general programming, so if this doesn''t belong here, apologize. Anyway, I was wondering if anyone has the code to a simple FPS counter, it sucks not knowing if anything you are doing is improving the framerate. Even if the framerate is output to a text file every update it would be fine. Thanks! -Taphreek Not a n00b, even if can''t write a basic FPS counter

Sponsor:

#2 VBlimits   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 March 2001 - 02:57 PM

HEHE Well i will give you a VB Sample

Private FPS as single
Private Time1 as long
Private P as byte

Private Sub Form_Load()
Time1 = getTickCount
do
DoEvents

.....
do your stuff here
.....

if p = 9 then
p=0
FPS = 10000/(getTickCount-Time1)
Time1 = getTickCount
debug.print FPS
end if
p=p+1
loop
End Sub



-VBLimits
Sorry about the Spelling..


#3 multitap   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 March 2001 - 03:20 PM

Uh, vb sucks, get out of here w/ that code.

Tap, search the forums for "fps counter" or something like that, the question has been asked alot, you should find it in no time



#4 lucid   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 March 2001 - 03:21 PM

yeah, some details about what your using would be nice...
Windows/Linux/Ect...
What windowing system(glut?), ect...

#5 Shannon Barber   Moderators   -  Reputation: 1362

Like
Likes
Like

Posted 10 March 2001 - 05:19 PM

  
float CGameEngine::CalcFrameRate(LARGE_INTEGER liNow_us)
{
//Original framerate calculation had really crappy twiddle

//framerate = 1000.0f / (float)elapsed;


const float e = 2.718281828f;

//0.5Hz filter, time in ms, so /1000.0

static float filter = (float)pow(e, -2.0f * 0.5f / 1000.0f);

static LARGE_INTEGER liTimeSnap_us;

//guess at initial framerate, so it doesn''t lag so bad on init

static float fFrameRate_fps = 33.3f;

float fElapsed_ms = (liNow_us.QuadPart - liTimeSnap_us.QuadPart) /1000.0f; //convert us to ms

liTimeSnap_us = liNow_us;

float factor = (float)pow(filter, fElapsed_ms);
float ifactor = 1.0f - factor;

if(fElapsed_ms<=0.0f)
//if the elasped time is 0, it took less than 5us to render the frame!

fFrameRate_fps = 200000.0f;
else
//filter, *1000.0f to convert ms to sec (again)

fFrameRate_fps = fFrameRate_fps * factor + ifactor * 1000.0f / fElapsed_ms;

return(fFrameRate_fps);
}

Single-pole, digitally filtered Frame Rate.

Magmai Kai Holmlor
- The disgruntled & disillusioned


#6 Hooloovoo   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 March 2001 - 11:06 PM

I give you a simple (however not quite as accurate) example in Allegro.

  
// Lions and tigers and global variables, oh my! :^)

volatile unsigned long fps = 0, framecount = 0, total_frames = 0;

void fps_proc()
{
fps = framecount;
total_frames += framecount;
framecount = 0;
}
END_OF_FUNCTION(fps_proc);

int GameLoop()
{
// Some stuff here

......
LOCK_VARIABLE(fps);
LOCK_VARIABLE(framecount);
LOCK_VARIABLE(total_frames);
LOCK_FUNCTION(fps_proc);
// Execute fps_proc once per second

install_int_ex(fps_proc, BPS_TO_TIMER(1));

do {
move_stuff();
draw_screen();
framecount++;
} while( !(want_exit) );
......
}



#7 +AA_970+   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 March 2001 - 03:30 AM

Ok here''s a simple way to do it, but it''s not that accurate:

int Get_FPS(void)
{
static DWORD fps_time1=GetTickCount();
static int fps_count, fps;
DWORD fps_time2 = GetTickCount();

fps_count++;
if(fps_time2-fps_time1 >= 1000)
{
fps_time1=GetTickCount();
fps=fps_count;
fps_count=0;
}

return fps;
}


You call this function at the end of every frame.

There is also the more accurate way which is done in the VB Sample. In C it would be similar something like...

DWORD Time1 = GetTickCount();

...Render Frame...

FPS = 10000/(GetTickCount()-Time1);
Time1 = GetTickCount();




Digital Radiation


#8 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 11 March 2001 - 04:14 AM

Well, if you''re using a Windows based system....

  

//DEBUG FILE STUFF

FILE *OutputFile;

//DEBUG************************************************************************

//Open Debug File

OutputFile = fopen("log.txt", "w+");
_LARGE_INTEGER PerfStart, PerfEnd, Freq;
unsigned long cyclespermilli;
char OutStr[100];
QueryPerformanceFrequency(&Freq);
cyclespermilli = Freq.QuadPart / 1000;
//DEBUG************************************************************************


//DEBUG**********************************************************************

QueryPerformanceCounter(&PerfStart);
//DEBUG**********************************************************************


//Do rendering functions and stuff here...


//DEBUG**********************************************************************

QueryPerformanceCounter(&PerfEnd);
//DEBUG**********************************************************************


//DEBUG**********************************************************************

long Time = (PerfEnd.QuadPart-PerfStart.QuadPart) / cyclespermilli;
memset(&OutStr, ''\0'', sizeof(OutStr));
sprintf(OutStr, "Milliseconds: %d\n", Time);
fwrite(&OutStr, strlen(OutStr), 1, OutputFile);
//DEBUG**********************************************************************






I hope that all looks good. Anyway. There are plenty of examples of using the Performance timer in the MSDN help at http://msdn.microsoft.com

Sorry it looks so bad. I cut out the rest of the engine and we plan on cutting anything with //DEBUG out of the code. =)

E.D.

#9 EnochDagor   Members   -  Reputation: 180

Like
Likes
Like

Posted 11 March 2001 - 04:19 AM

Sorry that was me in that last post. It doesn''t look quite the way I wanted it to but oh well.

Its really accurate, pretty fast, and down to millisecond level. (in case you don''t know your FPS is equal to 1/ms where ms is the milliseconds. So for example, my engine takes 9 milliseconds to do its rendering, therefore, I''m running at about 111 FPS. When I include data processing in the loop, it takes about 15 milliseconds which is 66 FPS. Etc... you get the point.)

E.D.

#10 Taphreek   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 March 2001 - 02:22 PM

Thanks for all the help. My only question left is I am using NeHe''s OpenGL text output and its kind of crappy. Anyone know anything better. Thanks again!

#11 Shannon Barber   Moderators   -  Reputation: 1362

Like
Likes
Like

Posted 12 March 2001 - 02:33 PM

I think that''s one of the better ones, actually.

Magmai Kai Holmlor
- The disgruntled & disillusioned





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS