/**
 *  OpenGL display function.
 *
 *  This function is called every 25 milliseconds by the update
 *  function.
 */
void glutDisplay (void)
{
    /**
     *  Update every node of OpenNI.
     */
    g_Context.WaitOneUpdateAll(g_DepthGenerator);

    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(40.0, 1.05, 1.0, 10000.0);
    gluLookAt(320.0, -300.0, 4200.0,
              320.0, 240.0, 1500.0,
              0.0,-1.0, 0.0);

    glMatrixMode(GL_MODELVIEW);

    glLoadIdentity();

    glPushMatrix();

    // Checking fot game starting and finishing
    g_SFBgame.checkUsers();

    if (g_SFBgame.isGameOn()) {
        
        g_UserDetector.changeStopDetection(true);
        g_SFBgame.checkGameOver();

        if (!g_SFBgame.isGameOver()) {
            g_BusterDetector -> detectPose();
            g_IceRodDetector -> detectPose();
        } 
        else {
            STATUS_CHECK(g_Context.StopGeneratingAll(), 
                "Context generation shutdown");
        }
    }
    else {
        // Detects poses
        g_ZamusDetector -> detectPose();
        g_LinqDetector -> detectPose();
    }
    
   
    /**
     *  Use the draw functions of every class to display the game with
     *  OpenGL.
     */
    g_SceneRenderer.drawScene();
    g_SFBgame.drawFireBalls();
    g_SFBgame.drawGameInfo();
    g_SFBgame.nextFrame();

    glPopMatrix();
    glutSwapBuffers();
}