Sign in to follow this  
Paddon

FPS Counter

Recommended Posts

I have implemented a Frames Per Second Calculator in my recent project but it is currently stationary while my camera is completly user controlled. I would like to have this implemented such that the stats i.e FPS, and X,Y,Z coords are always located in the same spot on the frame no matter where the camera is pointing. I was wondering if anyone knew a good algorithm for implementing this or where I may find a tutorial on the subject. I am using openGL and Glut if that makes a difference. Thank You

Share this post


Link to post
Share on other sites
Hi,

In OpenGL this can be done by setting the projection matrix to an Orthogonal (2d) one, gluOrtho2D. It sets the z range to -1,1 so be sure to give your text 2d coordinates (z=0). You should also push,reset,pop the modelview matrix because this will probably be altered by gluLookAt of glFrustum.
The following code should be called in the render routine (not in initialization or whatever)

this is the code i use:

//go 2d ortho
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0,800,0,600); //in glu.h

//get a clean modelview matrix
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

//use glRasterPos to set a coordinate and draw text, GLUT may have some
//alternate utility func for that.

//pop modelview and projection matrix for perspective use
glMatrixMode(GL_MODELVIEW);
glPopMatrix();

glMatrixMode(GL_PROJECTION);
glPopMatrix();

Good Luck & Greetings;

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this