GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


fps code by statler
1
 
int g_fps = 0;
int g_fpsNext = 0;
int g_seconds = 0;
int g_secondsLast = 0;

...

void renderscene()
{
    glLoadIdentity();
    glColor3f(1,1,1);
    showfps();
    glTranslatef(200,200,0);
    drawsomething();

    g_seconds = glutGet(GLUT_ELAPSED_TIME) / (1000.0f);
    if (g_seconds == g_secondsLast)
    {
        g_fpsNext++;
    }
    else
    {
        // a second has passed, update fps and current second
        g_secondsLast = g_seconds;
        g_fps = g_fpsNext;
        g_fpsNext = 0;
    }
}