Skip to main content
GameDev.net gamedev.net
🔒 Locked

Frames per second

Started by DorRaba Jan 19, 2004 at 10:31 AM 12 replies 650+ views
Original Post
DorRaba
DorRaba
How can I know how many frames per second, the program I write is creating, Do I need to do math colculation or can I find it in a DirectX library, the thing I''d like to know is how I''m showing the Frames pre second number onto the screen?
DDDDor RRRRaba
DorRaba
DorRaba
By the way I''m programming in C++ so a little example or source code can be very helpful.
DDDDor RRRRaba
Silex
Silex

bool CText::renderFPS(D3DCOLOR color, float timeDelta)
{
if( _font )
{
_frameCnt++;

_timeElapsed += timeDelta;

if(_timeElapsed >= 1.0f)
{
_fps = (float)_frameCnt / _timeElapsed;

sprintf(_fpsString, "%f", _fps);
_fpsString[8] = ''\0''; // mark end of string


_timeElapsed = 0.0f;
_frameCnt = 0;
}

_font->DrawText(20, 20, color, _fpsString);
}
return true;
}


I leave the rest up to you.
SnprBoB86
SnprBoB86
I have seen this asked before, but do not understand why.

When I first was wondering how to do this, I said to myself "If I can''t figure out how to calculate the number of frames per second then how in the world am I ever going to make it do anything cool?"

That said, I will give you several hints, but I hope noone actually answers your question so that you can learn on your own.

1) You have to code it yourself, it''s so simple that there aren''t any library functions for it in DirectX.
2) You do not actually need to wait one second to determin the actual number of frames per second, you can predict.
3) You may wish to take an average over a period of time (say 1/2 second) so that your FPS counter doesn''t flicker between two numbers every frame making it unreadable.

-SniperBoB-
DorRaba
DorRaba
What is the timeDelta variable, where is it come from, how do I declare it?
DDDDor RRRRaba
DorRaba
DorRaba
Forget it my mistake!!!
DDDDor RRRRaba
DorRaba
DorRaba
No, I steel doesn''t understandhow the timeDelta gets the time between the last time the function was called and this time?
DDDDor RRRRaba
DorRaba
DorRaba
But how do I know that One second past, in the example the timeDelta variable gives us the time between frame to frame, when I add all of the timeDelta and get to 1, the I know that 1 second has past, but where do I get the timeDelta, the time btween frame to frame?
DDDDor RRRRaba
Thunder_Hawk
Thunder_Hawk
Lookup GetTickCount().

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Forma
DorRaba
DorRaba
Where can I find it, can you give me a simple source code so I''ll see in which .h file this function is?
DDDDor RRRRaba
Erzengeldeslichtes
Erzengeldeslichtes
DorRaba, take a look at the C++ help files. GetTickCount is one of the functions that can tell you how much time has passed.

[edited by - Erzengeldeslichtes on January 19, 2004 12:20:15 PM]
----Erzengel des Lichtes光の大天使Archangel of LightEverything has a use. You must know that use, and when to properly use the effects.♀≈♂?
DrunkenHyena
DrunkenHyena
Here is a little FPS Timer class I threw together. You can use it as is, or just go through the code to learn how it works. There''s really very little to it.

http://www.drunkenhyena.com/docs/dhFPSTimer.phtml


Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena</FON

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.