Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Clarification (Projection Matrix & ModelView Matrix)?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member Newbie
    Join Date
    Apr 2013

    Clarification (Projection Matrix & ModelView Matrix)?

    I've seen numerous codes and everyone is putting glMode(GL_PROJECTION) in a certain place in the code. For example, some people put it in Reshape function, other put it Display function and other put it in initialize function. I know what they are for, however, I'm not sure where should I put them in my code and by which order? glLoadIdentity(), glMatrixMode(GL_PROJECTION), and glMatrixMode(GL_MODELVIEW).

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    The simple answer is: put it where you need it and nowhere else. Every state change incurs a cost and changing the projection is, in most cases done rarely. One case is the resize() function where a change of window dimension leads to a change is aspect ratio used during projection matrix calculation.

    Doing that stuff in display is, for instance, useful when you set up a temporary camera that needs a different projection than the main camera. A good example is shadow map calculation.

    In general: If you can, don't use legacy GL at all. Write your stuff yourself and forget about the the matrix stack altogether.

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2013
    Change the projection matrix when your screen changes aspect as thokra mentioned, or when you want to "zoom", or achieve some wide-angle look, or go orthographic for a very flat look. BTW, there is only one "wideness" of angle that will give you an undistorted projection, for example using gluPerspective() with a fovy value of the half-angle the height of your window makes from your eye, typically 10-30 degrees, exactly arctan(window height/2/eye-screen-distance), in degrees. You don't want to change your projection matrix every time you move or rotate the camera, that's the view matrix, or the view factor in the model-view matrix.

    A great tutorial to drop all the old legacy GL, and learn the new OpenGL design of versions 3 and 4 is at opengl-tutorial org (Search for opengl tutorial, and it comes up first.)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts