Change of coordinates with glFrustum

I am trying to use glFrustum for a perspective projection and as I understand glFrustum like glOrtho can be used to modify the mapping of our desired coordinate system to real screen coordinates (as read in Blue book). So, if I do


, it changes the coordinates to
_left = -1, right = 1, bottom = -1, top = 1 _in the form of cartesian coordinates.

I tried to draw a simple room (with 2 side walls) in this coordinate system by calling the following function in my draw method and it comes out drawing appropriately on the screen.

  void drawRoomWalls(){  
        //Left wall  
        glVertex3f(-1.0, 1.0, 0.0);  
        glVertex3f(-1.0, 1.0, -0.4);  
        glVertex3f(-1.0, -1.0, -0.4);  
        glVertex3f(-1.0, -1.0, 0.0);  
        //Right wall  
        glVertex3f(1.0, 1.0, 0.0);  
        glVertex3f(1.0, 1.0, -0.4);  
        glVertex3f(1.0, -1.0, -0.4);  
        glVertex3f(1.0, -1.0, 0.0);  

The function was called as follows:

        glFrustum(1.0, -1.0, -1.0, 1.0, 1.0, 1000.0);  
    glTranslatef(0, 0, -1.0);  

Subsequently, I tried to do an off-axis projection (by taking mouse as input instead of user’s head). The code is as follows:

    double fov, near, far;  
    double headX, headY, headZ;  
    float aspectRatio;  
    near = 1.0f; far = 1000.0f;  aspectRatio = ofGetWidth()/ofGetHeight();  
    fov = tan(DEG_TO_RAD * 30/2); //tan accepts angle in radians. tan of the half of the fov angle  
    fov = 0.5; //taken constant for now  
    double msX = (double)ofGetMouseX();  
    double msY = (double)ofGetMouseY();  
    double scrWidth = (double)ofGetWidth();  
    double scrHeight = (double)ofGetHeight();  
    headX = (msX / scrWidth) - 0.5;   
    headY = ((scrHeight - msY) / scrHeight) - 0.5;  
    headZ = -1.0;  
        glFrustum( near * (-fov * aspectRatio + headX),  
                   near * (fov * aspectRatio + headX),  
                   near * (-fov + headY),  
                   near * (fov + headY),  
    leftValue = near * (-fov * aspectRatio + headX); //for printing out on screen  
    rightValue = near * (fov * aspectRatio + headX); //for printing out on screen  
    bottomValue = near * (-fov + headY); //for printing out on screen  
    topValue = near * (fov + headY); //for printing out on screen  
    gluLookAt(headX * headZ, headY * headZ, 0, headX * headZ, headY * headZ, -1, 0, 1, 0);  
    glTranslatef(0.0, 0.0, headZ);  

I printed the values of leftValue, rightValue, bottomValue, topValue and when the mouse is in the center of the screen (the call to glFrustum looks like glFrustum(-0.25,0.25,-0.25,0.25,1.0,1000.0)

As per the above call, I expected the coordinate system’s left=-0.25, right=0.25, bottom=-0.25, top=0.25 and I was expecting the walls to disappear. However, the walls keep on appearing on the sides of the screen (with the scene being skewed and at the center being essentially the same as with off-axis projection). Why is it that the walls are still at the place on the sides (even though the coordinates changed to -0.25,0.25) or there’s something in glFrustum call that I am missing here about the coordinate system?

The leftValue, rightValue, topValue, bottomValue in your code can be equal only when aspect ratio is 1 (normally which is not the case).

The objects drawn on the screen disappearing or not disappearing depends upon the viewing volume that you define with glFrustum. You might have to check the arguments again to find out if the objects getting drawn are still inside viewing volume that you defined.