[SOLVED] How to calculate FPS in OpenGL?


void CalculateFrameRate()
    static float framesPerSecond    = 0.0f;       // This will store our fps
    static float lastTime   = 0.0f;       // This will hold the time from the last frame
    float currentTime = GetTickCount() * 0.001f;    
    if( currentTime - lastTime > 1.0f )
        lastTime = currentTime;
        if(SHOW_FPS == 1) fprintf(stderr, "\nCurrent Frames Per Second: %d\n\n", (int)framesPerSecond);
        framesPerSecond = 0;

Should I call this function in void play(void) or void display(void)?

Or it does not make any difference?


You should put it in the display loop. Here’s an article that explains some intricacies of game loops that you should read.

Answered By – DShook

Answer Checked By – Katrina (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.