Many of the online explanation of the above two functional principles of the article, but all are the more black, more and more confusing, in response to such problems, I think the project should be the first to abstract the problem into a simple mathematical model, and then in the mathematical perspective easier to understand.
OpenGL is a state machine, and each state variable is a Markov chain, which means that the latter change is based on the previous one.
This assumes that we are dealing with a three-dimensional model where the initial value of a state variable is m, where M is the matrix (which should be the unit matrix), if a series of state changes A1,a2,......,an.
That is, M multiplied by the n matrix--m*a1*a2*......*an, if we need to do a linear transformation of M, we need a linear transformation directly on M, assuming that the linear transformation is B, if the direct transformation, it becomes m*a1*a2*......*an*b, Seeing that this time B does not directly affect m body, this is because the matrix multiplication does not satisfy the commutative law. Only in very rare cases, matrix multiplication can be exchanged.
This time need to call the Glpushmatrix function, the previous transformation into the stack, m*a1*a2*......*an into M, and then do the transformation, then M*b, the last Call Glpopmatrix, the previous transformation out of the stack, then M*b*a1*a2*......*an, Achieve the results we want.
Glpushmatrix () and Glpopmatrix ()