In a newer OpenGL there is no matrix stack. I am working on a simple display engine, and I am going to implement the transformation stack.
What is a common strategy here? Should I build a push/pop stack, and use it with a tree representing my model? I suppose this is the "old" approach, that was deprecated in the newer OpenGL versions. Maybe then it is not the best solution (it was removed for some reason, unknown to me)
The matrix stack is used to concatinate matrices. Typically used for heirarchical models where a transformation is expressed relative to another. One can load a matrix on the stack and transform vertices in that space and then go back to the parent space by popping the stack.
Formula: X = x + tx Y = y + ty where tx and ty are translation coordinates The OpenGL function is glTranslatef( tx, ty, tz );
Each coordinate in OpenGL actually has four components, X, Y, Z, and W. The projection matrix sets things up so that after multiplying with the projection matrix, each coordinate's W will increase the further away the object is. OpenGL will then divide by w: X, Y, Z will be divided by W.
The GL_MODELVIEW matrix, as its name implies, should contain modeling and viewing transformations, which transform object space coordinates into eye space coordinates.
(it was removed for some reason)
It was removed, because in modern 3D applications the whole OpenGL matrix manipulation functionality was highly redundant. Any modern 3D application needs to deal with matrices anyway, and since OpenGL is not a proper matrix math library you'd use something like Eigen oder GSL or something homebrewn anyway.
A stack is still a very viable structure.
I'm not super experienced in this specifically, but I've done a fair bit of graphics/game development. I have more of an idea than an answer. In my opinion, the glPushMatrix
and glPopMatrix
stuff is deprecated because many developers wanted full control of the transforms rather than OpenGL taking care of that for them. So my idea is that they aren't deprecated because a matrix stack isn't the way to go, but rather because GL developers are supposed to take care of the matrices themselves, or use another library to do that for them.
In other words, a matrix stack is still probably the way to go, you just have to do it yourself, use deprecated functionality, or use an external library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With