Jump to content
  • Advertisement
Sign in to follow this  
C plus noob

Calculating FPS?

This topic is 4788 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Record the number of times you go through the mainloop over the course of a second:

currtime = timeGetTime();
nexttime = currtime + 1000;
fps = 0;

while (m_running) {
currtime = timeGetTime();
if (currtime > nexttime) {
// fps is your fps for this second
fps = 0;
nexttime = currtime + 1000;
} else {
fps++;
}

// do stuff
}

Share this post


Link to post
Share on other sites
You measure milliseconds with a suitable timer function. The code above uses timeGetTime(), which returns the time (in milliseconds) since the system booted. Its defined in <windows.h>, and you'll have to link in "winmm.lib" to use it.

DWORD timeGetTime(void)

Share this post


Link to post
Share on other sites
Quote:
Original post by C plus noob
ok sp i want to send FPS as setwindow text (i know how to do this) were would i put this loop in WinMain?


if (currtime > nexttime) {
// fps is your fps for this second
fps = 0;
nexttime = currtime + 1000;
char cMsg[256];
sprintf(cMsg,"APPTITLE :: %d", (int)fps);
SetWindowText(hwnd,cMsg)
} else {

Share this post


Link to post
Share on other sites
Quote:
Original post by C plus noob
ok sp i want to send FPS as setwindow text (i know how to do this) were would i put this loop in WinMain?

Presumably you've got a loop set up that continously updates the state of your app (does all the rendering and stuff). This is your main loop.

In the code sample I provided, the while (m_running) loop is a representative of your main loop. So take the rest of the stuff and stick it into your main loop in the appropriate places, as shown in the sample code.

Share this post


Link to post
Share on other sites

while(!done) // Loop That Runs While done=FALSE
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting?
{
if (msg.message==WM_QUIT) // Have We Received A Quit Message?
{
done=TRUE; // If So done=TRUE
}
else // If Not, Deal With Window Messages
{
TranslateMessage(&msg); // Translate The Message
DispatchMessage(&msg); // Dispatch The Message
}
}
else // If There Are No Messages
{
// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()
if (active) // Program Active?
{
if (keys[VK_ESCAPE]) // Was ESC Pressed?
{
done=TRUE; // ESC Signalled A Quit
}
else // Not Time To Quit, Update Screen
{
DrawGLScene(); // Draw The Scene
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
}
}

if (keys[VK_F1]) // Is F1 Being Pressed?
{
keys[VK_F1]=FALSE; // If So Make Key FALSE
KillGLWindow(); // Kill Our Current Window
fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode
// Recreate Our OpenGL Window
if (!CreateGLWindow("NeHe's OpenGL Framework",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
}
}



is this that loop?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!