OpenGL: transformation matrix matrix implementation

There is no matrix stack in the new OpenGL. I am working on a simple mapping engine and I am going to implement a conversion stack.

What is a common strategy? Should I create a push / pop stack and use it with a tree representing my model? I believe this is an "old" approach that is deprecated in new versions of OpenGL. Perhaps then this is not the best solution (for some reason it was deleted, unknown to me)

+6
source share
4 answers

(for some reason it was deleted)

It was deleted because in modern 3D applications all the functionality of manipulating the OpenGL matrix was extremely redundant. Any modern 3D application must deal with matrices anyway, and since OpenGL is not a suitable matrix math library, you will still use something like Eigen oder GSL or something home.

The stack is still a very viable structure.

+7
source

I am not very experienced in this, but I have done quite a bit of graphics / game development. I have more ideas than answers. In my opinion, the glPushMatrix and glPopMatrix are deprecated because many developers wanted to have full control over the transformations, not OpenGL, taking care of them. Therefore, my idea is that they are not outdated because the matrix stack is not suitable, but rather because the GL developers themselves have to take care of the matrices themselves or use a different library for this.

In other words, the matrix stack is still probably suitable, you just need to do it yourself, use legacy functions, or use an external library.

+2
source

Fixed pipeline functionality was deprecated because it was essentially fixed.

To support new tricks and such, as a rule, required new OpenGL functions, it became clear that the constant support of the requested functions means an increase in the size of the OpenGL API and a gradual increase in its number.

Meanwhile, the hardware was becoming more sophisticated and powerful, and OpenGL was not fully operational. Thus, the programmable pipeline was conceived.

With OpenGL3, the Kronos group is "deprecated" by the fixed pipeline function. This caused a huge noise, because there was so much code and so many talents that were invested in an established fixed pipeline, so they partially abandoned their decision by introducing the core and compatibility profiles. The main profile includes a new programmable pipeline model, and the compatibility profile includes a core plus most / all of the fixed functionality, allowing applications to use any model.

We are now working on OpenGL 4.2, and the compatibility profile still exists and shows no signs of extinction.

In short, the reason for the depreciation is not that the old model is not suitable for application programmers; rather, it was a heavier burden for developers. The actual model is strong enough, and many applications / developers who use programmable functions find themselves redistributing the main parts of the fixed functionality (glBegin, glEnd, matrix stacks, transformation calls, etc.).

So go ahead, implement your own matrix stacks. But, if you come up with an even better idea, share it with us :)

+2
source

Not sure if it suits you, but I applied two things for this. The first is a simple matrix stack class with all the usual methods, and the second is a stack-based RAII structure that allows me to scale the matrix using curly braces, i.e. When building, it stores a link to the matrix stack, and when destroyed, restores the stack matrix back to its previous state. Therefore you can write:

 MatrixStack stack; stack.push(rotate...) stack.push(translate...) { MatrixScope(stack); stack.push(rotate...) } ... back to previous stack state. 

And to add to this, it's just for convenience with some kinds of transformations. As a rule, for models consisting of a tree-like structure of the grid, all of them are transformed relative to each other, I will combine matrices from the root of the node before I do anything with the model. Thus, each grid has a local transform and a global transform, with the global transform being the actual transform for that grid relative to the root of the node. Therefore, there is no need to use a matrix stack there.

It’s a little different if you want to animate a part of the grid independently of the rest, so I also save the local transformation, and not drop it.

+2
source

Source: https://habr.com/ru/post/912488/


All Articles