PDA

View Full Version : Why should I use two matrix modes?



Condottiero
07-23-2011, 04:05 AM
Hey,

I've only a short question about the following code snippet.



void initialisiereSzene(void) {
glClearColor(1.0, 1.0, 1.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-5.0, 5.0, -5.0, 5.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPointSize(3.0);
}

Why should I use glMatrixMode(GL_PROJECTION) and glMatrixMode(GL_MODELVIEW)? What happens, if I use both modes like in the code snippet?

Greets,
Chris

BionicBytes
07-23-2011, 05:16 AM
These matricies are used in different stages of the OpenGL pipeline.
The ModelView matrix is used to position your model in front of the camera (the View part of the matrix) and also to scale, rotate and position your model in the world (the model part of the matrix). OpenGL combines both the model and view matricies and calls it the ModelViewMatrix. You are using this matrix when you issue cammand like glTranslatef or glScalef.

The ProjectionMatrix is used internally by OpenGL to take your draw calls and transform the scene into something that OpenGL can clip and position into the Window.

Dark Photon
07-23-2011, 10:29 AM
Here are some more reasons for that:

* http://www.sjbaker.org/steve/omniv/projection_abuse.html

Bottom line: some rendering operations need to happen in EYE-SPACE (an orthonormal space with the eyepoint at the origin), not CLIP-SPACE.