calculating fps and integer -> string conversion (in c)

Started by
2 comments, last by burns 22 years, 11 months ago
hi, How do i convert an integer to a string in c ? Also, i''ve just written a small app that plots a few pixels. Anyone know how to calculate fps ? I''m trying something with GetTickCount() but I dont know how to access the fps variable in win32. thanx
Advertisement
To answer your first question...
sprintf(MyString, "%i", MyInteger);

~~~~~~~~~~
Martee
http://www.csc.uvic.ca/~mdill
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
you could use aoti()
or sprintf, which will also work for floats etc...
and I think it would be sprintf("%d", myint)


to answer the second question:

    //On InitQueryPerformanceFrequency(&m_liFreq);//In the render loop		QueryPerformanceCounter(liStart_us);		m_fFrameRate_Hz = CalcFrameRate(*liStart_us, &m_fElapsed_sec);sprintf(szRate, "FPS: %.3f", m_fFrameRate_Hz);SetWindowText(hWndFrameRateTextBox, szRate);float CGameEngine::CalcFrameRate(LARGE_INTEGER liNow_us, float* pfElapsed_sec)	{	//Original framerate calculation had really crappy twiddle	//framerate = 1000.0f / (float)elapsed;	const float e = 2.718281828f;	//0.25Hz filter, time in ms, so /1000.0	static float filter = (float)pow(e, -2.0f * 0.5); 		//guess at initial framerate, so it doesn't lag so bad on init	static float fFrameRate_fps = 33.3f;	//float fElapsed_ms = (liNow_us.QuadPart - liTimeSnap_us.QuadPart) / 1000.0f;  //convert us to ms	float fElapsed_sec = float(liNow_us.QuadPart - m_liTimeSnap_us.QuadPart) / float(m_liFreq.QuadPart);	m_liTimeSnap_us = liNow_us;		float factor = (float)pow(filter, fElapsed_sec);	float ifactor = 1.0f - factor;		if(fElapsed_sec<=0.0f)		//if the elasped time is 0, it took less than 5us to render the frame!		fFrameRate_fps = 200000.0f;	else		//filter, *1000.0f to convert ms to sec (again)		fFrameRate_fps = fFrameRate_fps * factor + ifactor / fElapsed_sec;		if(pfElapsed_sec)		*pfElapsed_sec = fElapsed_sec;		return(fFrameRate_fps);	}    


Magmai Kai Holmlor
- The disgruntled & disillusioned


Edited by - Magmai Kai Holmlor on June 9, 2001 9:09:44 PM
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Could you explain the (1/e)^fElapsed_sec?
Keys to success: Ability, ambition and opportunity.

This topic is closed to new replies.

Advertisement