Preparation for Perspective Rendering 
  • reshape() in Example 3-1
  •  glMatrixMode(GL_PROJECTION) specifies projection matrix mode
  •  glLoadIdentity() resets matrix 
  •  glMatrixMode(GL_MODELVIEW) specifies modelview matrix mode
  • follow-up transformation calls will modify the modelview matrix

  •  

     
     
     
     
     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

The Viewport Transformation
  • The projection and viewport transformation determining the mapping of the scene onto the screen
  •  Projection: Mapping of verticies onto screen
  •  Viewport: Shape of the screen area
  •  glViewport() defines the available screen space in the window
  •  Camera analogy:  enlarging or reducing the image

  •  

     
     
     
     
     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

Drawing the Scene
  • Once all transformations have been made the scene can be drawn
  •  Every vertex is transformed by multiplication by the modelling and transformation matrices 
  • The projection matrix  is then multiplied (vertices are  clipped if outside viewing area) 
  •  Coordinates are then scaled before being drawn on the screen

  •  

     
     
     
     
     
     
     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

General-purpose transformation commands
  • Once all the necessary transformations have been specified, you can draw the scene (take the

  • photograph). 
  • As the scene is drawn, OpenGL transforms each vertex of every object in the scene by:
    • Multiplying by the modeling and viewing transformations. 
    • Multiplying by the  projection transformation 
    • Clipping if it lies outside the viewing volume described by the projection transformation. 
    • Transformed vertices are divided by w and mapped onto the viewport.

     
     
     
     
     
     
     
     
     
     
     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

General-Purpose Transformation Commands

void glMatrixMode(GLenum mode); 

    Specifies whether the modelview, projection, or texture matrix will be modified, using the argument GL_MODELVIEW, GL_PROJECTION, or GL_TEXTURE
 void glLoadIdentity(void); 
    Sets the currently modifiable matrix to the 4x4 identity matrix.
     
     
     
     
     
     
     
     
     
     
     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

General-Purpose Transformation Commands (cont)

void glLoadIdentity(void); 

    Sets the currently modifiable matrix to the 4x4 identity matrix. 
void glLoadMatrix{fd}(const TYPE *m); 
    Sets the sixteen values of the current matrix to those specified by m. 
void glMultMatrix{fd}(const TYPE *m); 
    Multiplies the matrix specified by the sixteen values pointed to by m by the current matrix and stores the result as the current matrix.
Remember that you might be able to maximize efficiency by using display lists to store frequently used matrices (and their inverses) rather than recomputing them (because of inverse calculations for normal & clipping planes)
     
     
     
     
     
     
     
     
     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

C Language Caveat with OpenGL
    Caution: If you're programming in C and you declare a matrix as m[4][4], then the element m[i][j] is in the ith column and jth row of the OpenGL transformation matrix. This is the reverse of the standard C convention in which m[i][j] is in row i and column j. To avoid confusion, you should declare your matrices as m[16].
     
     
     
     
     
     
     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

Matrix Multiplication

All matrix multiplication with OpenGL occurs as follows: Suppose the current matrix is C and the matrix specified with glMultMatrix*() or any of the transformation commands is M. After multiplication, the final matrix is always CM. Since matrix multiplication isn't generally commutative, the order makes a difference.

     
     
     
     
     
     
     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

Viewing and Modeling Transformations 
  •  Viewing and modeling transformations are "inextricably related" in OpenGL and are in fact combined into a single modelview matrix
  •  The duality of viewing/modeling transformations allows the application developer to think of trasformations as either:
    • moving the "camera" (viewpoint) or
    • moving the model
  •  glMatrixMode(GL_MODELVIEW) must be called before any transformation

  •  

     
     
     
     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

Thinking About Trasformations
  • Figure 3-4
  •  A counter-clockwise rotation about Z and then a translation
  • Rotation first: object is located on the X-axis
  • Translaton first: object is above the X-axis

  •