PDA

View Full Version : Displaying the FPS on Screen



Joe_Oliveri
09-20-2004, 06:40 PM
I have read alot of tutorails but they never comment on this, and in some of the tutorials you have to all this crap built into it, could some one show me how to display the FPS on screen with a basic text whit out the mombo jombo crap from other tutorials.

Edit: Even a link to a tutorial that discribes this would be great.

any reply is welcome, Thank you for your help.

mikael_aronsson
09-20-2004, 09:57 PM
Take a look at any tutorial that renders text.

There is no simple portable way of doing this because win32 use wgl and X uses glX functions to get a font converted to triangles/lines, you would need to use a font bitmap (the easiest solution) or use a ttf library like FreeType.

But there are tons of opengl tutorials on rendering text with opengl, have a look at those.

Mikael

Obli
09-21-2004, 12:35 AM
There's a C lib function which takes a float arg and returns a string of that float. It will come in handy. It's called ecvt if I am not wrong.
Mind you, I hate its syntax so I did it from scratch.

zukko
09-21-2004, 08:46 AM
void fps()
{
static float fps=0.0f;
static float before=0.0f;
static char strFPS[20] = {0};
static float now = (GetTickCount()*0.001f);

++fps;

if(now-before>1.0f)
{
before=now;
sprintf(strFPS,"FPS: %d",int(fps));
fps=0.0f;
}
}

just call fps() in your main loop.
hope it helped

Joe_Oliveri
09-21-2004, 05:36 PM
Ok thank you guys very much for the help I got it running now! ^_^

robosport
09-22-2004, 04:08 PM
Any Windows users interested in this topic that don't want to add additional code, check out Fraps at the fraps.com web site. It automatically overlays the current FPS onto the OpenGL window. It even works with my multi-view application. Pretty cool.

No I'm not affiliated with them in any way, I just thought their product was right on topic.

robo

Joe_Oliveri
09-28-2004, 09:50 AM
Thanks everyone that Fraps program is really cool. Thank you for the link.