FPS in a game

I develop my own 3d game. And I have ported it to Linux platform. Tell me, please, how I can implement the fps-counter in Linux version of my game.

i tont know, how you did it before… i dont think it is different on other operating systems :slight_smile:

if you could describe your problem a bit more, i´ll be able to help you!!


I think the OP asks for a way to measure time precisely on linux.

Yes, I don’t know how I can measure time precisely on Linux. In Win32 applications we use GetTickCount() to do this. And what about Linux???

I am using “gettimeofday”…
There seems to be a “clock_gettime” but I didn’t tried it.

try this:


timeval		tv, tv_zero;
int		Frame = 0, NumFrames = 100;
float		FPS, T, prevT;

int main(int argc, char *argv[]){

gettimeofday(&tv_zero, NULL);		// GET TIME VALUE AT PROGRAM START

while(1) {
        gettimeofday(&tv, NULL);	// GET CURRENT TIME
        T = (float)(tv.tv_sec-tv_zero.tv_sec) + .000001*(tv.tv_usec-tv_zero.tv_usec);

        if(Frame%NumFrames == 0) {
		printf("	T = %5.2f, %4.1f FPS
", T, FPS);
                FPS = (float)NumFrames / (T-prevT);
                prevT = T;}

        Frame ++; } 

Thank you, GreetingsFromMunich. I’ll check your imlementation in my game.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.