Displaying the FPS on Screen

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.

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

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.

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

Ok thank you guys very much for the help I got it running now! :slight_smile:

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

Thanks everyone that Fraps program is really cool. Thank you for the link.