Search code examples
iphoneopengl-esobjective-c++

Changing glFrustum doesn't change viewport


I have a cube on the screen, I want to give the effect of zooming out so I was tweaking the frustum to be larger and larger. Here is the code:

- (void)Draw {

    EAGLView* videoController = [EAGLView Instance];
    [videoController BeginDraw];

    glClearColor(0.1f, 0.7f, 0.1f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glViewport(0, 0, videoController.mBackingWidth, videoController.mBackingHeight);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    float mAspectRatio = 1.6666;
    static float mHalfViewAngleTan = 0.1;
    mHalfViewAngleTan += 1.1;
    float mNearZClip = 1.0;
    float mFarZClip = 1000.0;
    glFrustumf( mAspectRatio*-mHalfViewAngleTan, mAspectRatio*mHalfViewAngleTan, -mHalfViewAngleTan, mHalfViewAngleTan, mNearZClip, mFarZClip );

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    static float rotZ = 0.0f;
    ++rotZ;
    if(rotZ > 360)
        rotZ = 0;

    glRotatef(rotZ, 0, 0.5, 0.5);

    RenderModel(modelObj);

    [videoController EndDraw];
}

The glRotate is working correctly. However as mHalfViewAngleTan gets larger nothing seems to be happening, the scene changes in no noticeable way. I have tried smaller and larger numbers for the amount mHalfViewAngleTan increase per frame. Changing the Near and Far plane are also working correctly.

There are no glMatrixMode/glPushMatrix calls inside RenderModel. It Enables and Disables client state, sets up glVertPointer's and call glDrawArray.

All this code is in an .mm file calling into .cpp files.


Solution

  • I had this problem in the past. I solved it by directly including the Open GL 1.1 or 2.2 headers. Not quite sure why that fixed it.