This returns the values of the modelview matrix in column major format. So multiplying this matrix with the (0,0,0,1) vector is equal to the last column which is

so this would be the point (0,0,0)?
OK. But what about things like gluLookAt?
In my special case, I am working in an Ortho-Setup and I just shifted my eyepoint 5 backwards in z-dir:

Hmm, but these x2,y2,z2 and w2 that you called to be in “world” space, haven’t they been transformed from world space into a “perspective” world space already? I’m quite new to OpenGl, so I’m not sure about this question.
I mean that the position of the viewer is the first (or in reality the last) thing that is done to the MV matrix, isn’t it? Take my example from the beginning. I translate my viewpoint in z-dir:

glTranslate(0,0,-5)

ok. So if in this case I put just one vertex (0,0,0) in my scene, then the MV matrix multiplied by (0,0,0,1) would give me (0,0,-5) which is not what I want! I would like to get (0,0,0) back!

Hope you can understand me.
In principle I would like to obtain hte MV matrix without the initial viewpoint and glFrustrum and gluLookat stuff.

You’re right, Oliver. As the term “model-view-matrix” indicates, it is used to transform from model space (also called object space) to view space (also known as eye space).

There is no “model-world-matrix” in GL. You have to track it by yourself. This is due to the fact, that a “world” semantically depends on the kind of scene you want to render.

Next question: are there any other “free” matrix stacks in OpenGl, besides the Projection and the Modelview matrix? Or how would you track such transformations efficiently? Using your own matrix datastructure?

No. The perspective transformation is done by the projection matrix, not the modelview matrix.

The modelview matrix transforms a point specified with glVertex4f(x1,y1,z1,w1) (object space) to the camera coordinate system (x2,y2,z2,w2) (eye-space). Finally, the projection matrix transforms the (x2,y2,z2,w2) coordinates to screen space.

It all depends how you look at it. Suppose you start with

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//some matrix ops here

and you want it to translate 5 units to the right of the viewer, it becomes:

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(5.0,0.0,0.0);
//some matrix ops here

So you would like to know the coordinates of a point in object space so that after transformation by the modelview matrix it return 0,0,0?
In that case you should calculate the inverse of the modelview matrix and multiply it with (0,0,0,1). Then it makes sense that if you multiply the modelview matrix with this result, you get (0,0,0) back.

@CatDog: You’re right. Thanks for clearing that up for Oliver. Since there is no “world-space” in OpenGL I tend to consider world-space to be equal to eye-space. My bad

Next question: are there any other “free” matrix stacks in OpenGl, besides the Projection and the Modelview matrix? Or how would you track such transformations efficiently? Using your own matrix datastructure?

The latter. Also remember that there is a driver/hardware dependant limit for matrix stack depth. The MV stack is very useful if you want a quick way to modify the current matrix.

If you’re for example trying to render a scene tree, that contains local transforms at its nodes, this is not a good way to go. What if your tree depth is bigger than the maximum matrix stack depth?

So if you don’t know how many matrices you’re going to push, use your own stack and simply glLoadMatrix before rendering a node.

NiCo: The beauty of the “world” is in the eye of the viewer.

The only matrix stacks in OpenGL are GL_TEXTURE, GL_MODELVIEW, GL_COLOR and GL_PROJECTION.

Like CatDog already pointed out, if you have a lot of transforms to track it’s best to write your own matrix stack and use glLoadMatrix and glMultMatrix.

I don’t think using display lists to track the changes helps you to avoid the matrix stack size limit.