I'm starting to understand a bit of OpenGL stuff, and I see a lot of examples that call function calls glMatrixMode.
glMatrixMode
From what I have assembled, setting this GL_MODELVIEW or GL_PROJECTION (etc.) will activate this particular transformation matrix and all subsequent calls to the matrix transformation function (glTranslatef, glPushMatrix, glLoadIdentity, glLoadMatrix, etc.) will only affect the active matrix .
I do not understand why there are 3 (4 in some cases) different matrices? Which one should I use? (I'm probably going to get a lot of “Using Shaders,” but I can't. Limited at school ...) When do I need to switch and activate another matrix? What is the advantage of using all of them, and not just one?
Thanks for any help :)
glMatrixMode does not activate matrices. The OpenGL fixed pipeline uses 3 matrices (sometimes 4): two of them are responsible for transforming the geometry, one for transforming the texture space (and some for color adjustments). These matrices are used all the time.
The modelview matrix is used to move the geometry. Since OpenGL does not have a “camera”, the viewer is positioned by moving the entire geometry in the reverse (= reverse) movements of the “camera”.
projection , .. .
. , (s, t, r, q) , . OpenGL . .
( ). , . , ? , , . RGB- > XYZ , . , .
glMatrixMode , . :
glModelviewLoadIdentity glModelviewLoadMatrix glModelviewMultMatrix glModelviewRotate glModelviewTranslate glModelviewScale glModelviewPushMatrix glModelviewPopMatrix glProjectionLoadIdentity glProjectionLoadMatrix glProjectonMultMatrix glProjectionRotate glProjectionTranslate glProjectionScale glProjectionPushMatrix glProjectionPopMatrix
.. , , glFrutum . .
, . . , , , . .
, (.. " " ). , , .
OpenGL , . , . , , , , glTranslatef, .
OpenGL ( ), , , .
EDIT: , , . " ", , - "", . ( "" ) " ", "" , , .. .. ..
( , ). google opengl, , , , , this.
, ( opengl.org), (, , ) , .
, glMatrixMode(GL_PROJECTION) , gluPerspective() (, , glOrtho()), , . , .
glMatrixMode(GL_PROJECTION)
gluPerspective()
glOrtho()
GL_MODELVIEW //. , = GL_PROJECTION * GL_MODELVIEW * . GL_MODELVIEW , GL_PROJECTION, .
GL_MODELVIEW
This is because matrix multiplication is not commutative. If you had only one matrix mode, a new transformation will always occur after all existing ones, and this is not always desirable.
By saving several matrices that are effectively multiplied together for each part of the geometry, you can, for example, have both translations in order to visualize different bits of the object, as well as transform the point of view, and be able to adjust them independently of each other.