Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL: Implementing transformation matrix stack

Tags:

opengl

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)

like image 760
Jakub M. Avatar asked Apr 05 '12 10:04

Jakub M.


People also ask

What is matrix stack in OpenGL?

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.

How do I transform in OpenGL?

Formula: X = x + tx Y = y + ty where tx and ty are translation coordinates The OpenGL function is glTranslatef( tx, ty, tz );

How does OpenGL matrix work?

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.

What OpenGL function implements the viewing transformation?

The GL_MODELVIEW matrix, as its name implies, should contain modeling and viewing transformations, which transform object space coordinates into eye space coordinates.


2 Answers

(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.

like image 134
datenwolf Avatar answered Sep 21 '22 12:09

datenwolf


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.

like image 40
Andrew Rasmussen Avatar answered Sep 22 '22 12:09

Andrew Rasmussen