glMatrixMode() - I just don't get it.

Started by
3 comments, last by AndreTheGiant 21 years, 7 months ago
Hello. Im trying to learn Opengl. Ive got what I think are some great books on the subject, but neither of them have explained this one seemingly simple, seemingly fundamental topic very well. What is the deal with the glMatrixMode() commands? So far Ive come accross 3 parameters for this function: GL_PROJECTION, GL_MODELVIEW and GL_ORTHO-something. My books use these functions freely and dont really explain when to use which mode, or what each mode does. Ive been getting by by finding examples in the textbook that are similar to the program that I am creating, and copying their usage of this function. Also, is there anything special I should know about glMatrixMode() with respect to making 2D graphics? For example, I have recently been creating a lot of 2D programs using gluOrtho2d(...), and it seems that everything I *thought* I knew about glMatrixMode() doesn''t apply. Thanks in advance. ----- It''''s not my fault I''''m the biggest and the strongest; I don''''t even exercise!
Advertisement
The matrix mode is one of opengl''s states it remembers. It means more or less that subsequent operations will be performed on whatever matrix you specify in glMatrixMode() until you change it to a different mode. I think the only things you can pass to it are GL_PROJECTION, GL_MODELVIEW, and GL_TEXTURE
quote:Original post by AndreTheGiant
Hello. Im trying to learn Opengl. Ive got what I think are some great books on the subject, but neither of them have explained this one seemingly simple, seemingly fundamental topic very well.

What is the deal with the glMatrixMode() commands? So far Ive come accross 3 parameters for this function: GL_PROJECTION, GL_MODELVIEW and GL_ORTHO-something.


I believe GL_ORTHOGRAPHIC and GL_PROSPETIVE are projection modes rather than matrix modes. A matrix mode deals with what coordinate system you are manipulating at the time. I''m not sure enough on the definitions to really be a reliable source, perhaps someone can confirm/correct my information.
SpiffGQ
I''m a begginer too, so take this with some kind of reserve

the GL_PROJECTING makes the projection matrix the current one ,GL_MODELVIEW makes the model one current and the GL_ORTHOGRAPHICS I''ll explain below

The projection matrix is the one which affects projection. I don''t know much about it

The modelview matrix is the one that affects how the model is like. Rotation, translation and such... If you want to stretch, translate, scale or rotate a model, this is the right one

The ortographics mode then switches to a 2d mode... You resize the 2d logical viewport by the glOrtho then. And can draw in pure 2d, whatever comes to you mind. In games, this is used to draw health indicators, character screens and such...
let the red book be your guide:

"Before glFrustum() can be called to set the projection transformation, some preparation needs to happen. As shown in the myReshape() routine in Example 3-1 , the command called glMatrixMode() is used first, with the argument GL_PROJECTION. This indicates that the current matrix specifies the projection transformation; the following transformation calls then affect the projection matrix. As you can see, a few lines later glMatrixMode() is called again, this time with GL_MODELVIEW as the argument. This indicates that succeeding transformations now affect the modelview matrix instead of the projection matrix. See "Manipulating the Matrix Stacks," for more information about how to control the projection and modelview matrices."

from online openGL redbook (http://fly.cc.fer.hr/~unreal/theredbook/) chapter 3

basically GL_PROJECTION is the matrix that sets up the view frustum. GL_MODELVIEW manipulates objects in the world matrix. GL_ORTHO i believe sets you into 2D mode, but i'm not sure about that one. anyway read the online book.

-me

[edited by - Palidine on September 3, 2002 8:22:09 PM]

This topic is closed to new replies.

Advertisement