calculating frame rate |
Author :
opendep
Post Date :
2008-02-08 12:57
Posts :
10
|
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...
|
Author :
grant
Post Date :
2008-02-08 13:59
Posts :
117
|
Hi,
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.
Regards,
Grant |
Author :
opendep
Post Date :
2008-02-11 12:47
Posts :
10
|
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.. |
Author :
grant
Post Date :
2008-02-11 12:51
Posts :
117
|
Hi,
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?
Regards,
Grant |
Author :
opendep
Post Date :
2008-02-11 12:55
Posts :
10
|
hi grant,
its just displaying the static text "Frame rate :" |
Author :
grant
Post Date :
2008-02-11 13:03
Posts :
117
|
Hi,
Try using the sprintf function to build your string to print :
e.g. sprintf(buf, "Frame rate : %d", fps);
Regards,
Grant |
Author :
opendep
Post Date :
2008-02-11 14:13
Posts :
10
|
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.
|
All Rights Reserved, © Zeus Communications, Multimedia & Development 2004-2005