Login | Register

Home > Forums > OpenGL > calculating frame rate Page :  1 
calculating frame rate
hi.. can anyone kindly tell me how to calculate the frame rate in openGL?

my program displays multicoloured cubes (around 1000) forming a grid like structure which rotates and translates on mouse click and I need to calculate its frame rate to compare with other renderers...


Firstly, use a function like time or GetTickCount to get a value for a particular point in time.

Then have the following global variables :

int fpsCounter;
int currentFPS;
long lastTime;

Then in your update loop, increase fpsCounter by 1 and then check if the current time - lastTime is longer than a second. If it is, then reset lastTime to the current time and reset fpsCounter to 0.

Before resetting fpsCounter to 0, record its value in currentFPS to store your current frames per second.

Hope this helps.


Hi Grant,

Thanks a lot.. but can u also help me with printing the variable currentFPS on the screen along with the cube grid.. ive tried the bitmap method to display text but it isnt displaying the value of the variable...

Thank you..

You will have to give more information on what is happening. What is it displaying if it isn't displaying the value of the variable?

hi grant,

its just displaying the static text "Frame rate :"

Try using the sprintf function to build your string to print :

e.g. sprintf(buf, "Frame rate : %d", fps);

Hi Grant,

sprintf() is doing the job with a single 3D figure.

But in my program, the display function is called 1000 times in nested for loops. The for loops are present in another function looping() which is called once in the function

LONG WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

so when I use sprintf() or bitmaps here, its resulting in a win32 runtime exception.

And I have another question. I have added the zoom functionality to the cube grid. So can i mention the specific location for the text using glrasterpos2f ?

Thank you.

Home > Forums > OpenGL > calculating frame rate Page :  1 

You need to be logged in to reply to this topic.

All Rights Reserved, © Zeus Communications, Multimedia & Development 2004-2005

Read the Disclaimer