Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the point of the matrix stack in OpenGL?

Tags:

c

opengl

Why would I use OpenGL's matrix stack (as opposed to wrapping my own matrix class and just using that)? I'm not really sure why it is so complicated for such a simple task. Is there's some special use case for it?

If it isn't necessary, what's a good replacement for it?

like image 632
Clark Gaebel Avatar asked Sep 20 '10 22:09

Clark Gaebel


4 Answers

OpenGL's matrix stacks (there are multiples--one for each matrix mode) are intended for use with hierarchical models. That is, you can define the rigging of a child object (say, a wheel) with respect to its parent body (say, a car), without regard to the location/orientation of the parent when the child is drawn. That is, it allows you to compose transforms easily and intuitively.

The matix stacks (and GL matrix operations in general) are no substitute for a general purpose matrix math library. They simply exist to allow composed transforms to be efficiently applied to vertex data. As others have said, this functionality has been removed from OpenGL with the demise of the fixed-function pipeline, because the needs of shader programs are less uniform than the needs of the old pipeline.

like image 183
Drew Hall Avatar answered Oct 29 '22 20:10

Drew Hall


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. You can manage all this yourself in code, and frequently you would prefer to - in particular the case where the matrices are used for other thing besides simply drawing or when you access them often. An animation system would be a classic example.

like image 37
Montdidier Avatar answered Oct 29 '22 20:10

Montdidier


You'd mostly use the built-in matrix stacks because OpenGL will apply them automatically. They've been removed in recent versions of OpenGL, so at least a few people apparently believe they're unnecessary. Personally, I think that was a poor decision, but such is life. The alternative is to implement them yourself -- the only consolation being that for most uses of 3D graphics, you're generally going to have to do some matrix multiplication (and such) yourself anyway, so it frequently doesn't make a lot of difference.

like image 43
Jerry Coffin Avatar answered Oct 29 '22 20:10

Jerry Coffin


It isn't necessary - you can do all your own matrix work yourself and call glLoadMatrix all the time - but also, it isn't necessary to replace it. You just make life difficult if you're using VBOs and display lists.

like image 35
Will Avatar answered Oct 29 '22 21:10

Will