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

Frames Per Second

Started by Newbie00 Apr 17, 2004 at 9:47 PM 1 replies 450+ views
Original Post
Newbie00
Newbie00
Here is the code I am using for it.
void FrameCount()
{
	INT64 NewCount = 0;
	static INT64 LastCount = 0;
	INT64 Difference = 0;

	QueryPerformanceCounter( (LARGE_INTEGER*)&NewCount );

	g_FrameCount++;

	Difference = NewCount - LastCount;

	if( Difference >= g_Frequency )
	{

		g_FrameRate = g_FrameCount;
		g_FrameCount = 0;

		LastCount = NewCount;
	}

}
 
Here is what i use to display the frames.
	char string[4];

	ZeroMemory( &string, sizeof( string ) );

	itoa( g_FrameRate, string, 10 );
	lpFont->DrawText(NULL, string, -1, &font_rect, DT_LEFT|DT_NOCLIP, 0xFFFFFFFF);

 
It displays a 1 no matter what. What am I doing wrong here?
SnakeHunta
SnakeHunta
what value are you using for g_frequency? I''m guessing you are using the frequency obtained from QueryPerformanceFrequency()...thus, every time you call your code it is executing

if( Difference >= g_Frequency )
{
g_FrameRate = g_FrameCount;
g_FrameCount = 0;
LastCount = NewCount;
}

And because you are always setting FrameCount to 0 and then incrementing each function call...you are always getting 1.
Newbie00
Newbie00
INT64 g_Frequency = 0;

what should I be doing then?

[edited by - Newbie00 on April 17, 2004 11:08:57 PM]

Topic Locked

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

Sign in to reply to this topic.