Shadow Map - Code Sample

/*
Draw the shadows to the frame buffer.
*/
static inline void DrawShadows(void)
{
    float Angle = getLightCenter();// * (float(M_PI)) / 180.0f;
    float vAngle = getLightCenterV();// * (float(M_PI)) / 180.0f;
    const float Near = getLightNear(); //5.5f;
    const float Far = getLightFar(); //6.5f;
    float LightAngle = tan(getLightFrustrumAngle() * (float(M_PI)) / 90.0f);

    //We aren't texturing here.
    glDisable(GL_TEXTURE_2D);

    //We have a special projection matrix for the light
    //Save the current matrix and setup the light's matrix
    glMatrixMode (GL_PROJECTION);
    {
        glPushMatrix();
        glLoadIdentity();

        glFrustum (-LightAngle * Near, LightAngle * Near, -LightAngle * Near, LightAngle * Near, Near, Far);
    }
    glMatrixMode (GL_MODELVIEW);

    glPushMatrix();
    glLoadIdentity();

    //Position Light
    glRotatef(vAngle, 1.0f, 0.0f, 0.0f);
    glTranslatef(0.0f, 0.0f, light_distance);
    glRotatef(Angle, 0.0f, 1.0f, 0.0f);

    //Save the matrices used to draw the object for later use
    glGetFloatv(GL_PROJECTION_MATRIX, *LightPMatrix);
    glGetFloatv(GL_MODELVIEW_MATRIX, *LightMVMatrix);
    GL_CHECK_ERROR();
    SetupFramebufferObject(FBO_ShadowMap, 0, 0, ShadowMap);
    GL_CHECK_ERROR();
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //Trasform and draw the object
    GL_CHECK_ERROR();
    glPushMatrix();
    TransformObject();
    glColor3f(1.0f, 0.0f, 0.0f);
    DrawObject();
    glPopMatrix();

    GL_CHECK_ERROR();
    glColor3f(0.0f, 0.0f, 1.0f);
    if (displayGround) DrawGroundPlane();

    GL_CHECK_ERROR();
    ClearFramebufferObject(false);

    //Reset the matrices
    glMatrixMode (GL_PROJECTION);
    {
        glPopMatrix();
    }
    glMatrixMode (GL_MODELVIEW);
    glPopMatrix();

    //Reenable texturing
    glEnable(GL_TEXTURE_2D);
}