This topic is now archived and is closed to further replies.


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

Recommended Posts

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

Share this post

Link to post
Share on other sites
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 Init


//In the render loop

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 the elasped time is 0, it took less than 5us to render the frame!

fFrameRate_fps = 200000.0f;
//filter, *1000.0f to convert ms to sec (again)

fFrameRate_fps = fFrameRate_fps * factor + ifactor / fElapsed_sec;

*pfElapsed_sec = fElapsed_sec;


Magmai Kai Holmlor
- The disgruntled & disillusioned

Edited by - Magmai Kai Holmlor on June 9, 2001 9:09:44 PM

Share this post

Link to post
Share on other sites