calculating fps and integer -> string conversion (in c)
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
To answer your first question...
sprintf(MyString, "%i", MyInteger);
~~~~~~~~~~
Martee
http://www.csc.uvic.ca/~mdill
sprintf(MyString, "%i", MyInteger);
~~~~~~~~~~
Martee
http://www.csc.uvic.ca/~mdill
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:
Magmai Kai Holmlor
- The disgruntled & disillusioned
Edited by - Magmai Kai Holmlor on June 9, 2001 9:09:44 PM
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement