FPS Counter
Here
Or use something like this (This will show up in the title bar of the window):
Or use something like this (This will show up in the title bar of the window):
//Calculate Framerate::http://www.gametutorials.net/void CalculateFrameRate(){ static float framesPerSecond = 0.0f; static float lastTime = 0.0f; float currentTime = GetTickCount()*0.001f; ++framesPerSecond; if( currentTime - lastTime > 1.0f ) { lastTime = currentTime; if(!Option.fullscreen) { sprintf(strFrameRate, "Program Title | FPS: %d", int(framesPerSecond)); SetWindowText(hwnd, strFrameRate); } else { //Display in Game } framesPerSecond = 0; }}
using QueryPerformanceFrequency() and QueryPerformanceCounter() declared as a LONG_INTEGER in direct x is a way, the long integer is used as you may be dealing with a lot of numbers
then you would need something like
Delta.QuadPart = Timer.QuadPart - LastQuery.QuadPart;
LastQuery.QuadPart = Timer.QuadPart;
then a getfucntion could be called which divides the resulting delta and freq quad parts
then you would need something like
Delta.QuadPart = Timer.QuadPart - LastQuery.QuadPart;
LastQuery.QuadPart = Timer.QuadPart;
then a getfucntion could be called which divides the resulting delta and freq quad parts
Thanks for the help. Here is what I've come up with:
How's it look? The timer seems to be extremely innaccurate at a 50ms update time.
#define FPSUPDATETIME 50 // Number of ms until FPS is updatedDWORD StartTime = 0;DWORD DeltaTime = 0;DWORD LastTime = 0;DWORD FPS_Time = 0;DWORD FPS_Frames = 0;DWORD FPS_FinalFrames = 0;while(true){ // Setup RTS StartTime = GetTickCount(); DeltaTime = StartTime - LastTime; if(DeltaTime > SAFETIME) DeltaTime = SAFETIME; LastTime = StartTime; // Calculate FPS FPS_Time += DeltaTime; ++FPS_Frames; if(FPS_Time >= FPSUPDATETIME) { FPS_FinalFrames = FPS_Frames * (1000 / FPSUPDATETIME); FPS_Time -= FPSUPDATETIME; FPS_Frames = 0; } /* Display FPS_FinalFrames here */ /* Perform other game-related processes below this */}
How's it look? The timer seems to be extremely innaccurate at a 50ms update time.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement