Simple projection matrix question

Hello forum again,

Following the homogeneous co-ordinate system, I wanted to add a simple perspective projection matrix to my OpenGL code.

Wikipedia states that the “simplest” or “normal” perspective projection matrix is:

1 0 0 0
0 1 0 0
0 0 1 0
0 0 1 0

In a 4-co-ordinate system (x, y, z and w) this sets w = z so that the actual plotted points are x/z, y/z, etc.

I’m finding that I have to use the following for anything to be drawn on the screen:

float m[16] = {1,0,0,0, 0,1,0,0, 0,0,1,1, 0,0,0,1};

I get that the matrix might need to be a row/column transposed version (can anyone verify this?) but it doesn’t explain the bottom-right corner coefficient needing to be a “1”.

Or maybe it’s because this sets up w = w + z, so that dividing I get x = x / (w + z), y = y / (w + z), z = z / (w + z), i.e. rather than x = x / w, y = y / w and z = z / w where in the last case, w = z so z = z / z = 1 and therefore the depth information disappears.

Anyone got a typical projection matrix they use or a link to a decent projection matrix tutorial. Is my understanding correct?

Have a look at th glu library - it is easier than working out these matrices for yourself.

Generally OpenGL examples are column-major matrices but it does not have to be - it all depends on what you want to do.

See the perspective matrix in the back of the Red Book, or those listed here:

Thanks both of you. Now using gl_frustum but still have some wierd results. May post these here…

Sure thing.