Results 1 to 3 of 3

Thread: Clarification (Projection Matrix & ModelView Matrix)?

  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.)

Similar Threads

  1. getting the inverse modelview projection matrix
    By cherryyosh in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-04-2009, 08:09 AM
  2. modelview/projection matrix multiply order
    By mjs1 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-20-2004, 04:17 PM
  3. Getting the inverse Modelview*Projection Matrix
    By Jan in forum OpenGL: General
    Replies: 2
    Last Post: 05-17-2004, 01:46 AM
  4. PROJECTION / MODELVIEW matrix analogy?
    By Andrea Rossini in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-22-2002, 11:25 PM
  5. Difference between Modelview matrix and projection matrix
    By aphlai in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-22-2001, 07:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean