gluPerspective question

I was trying to create the projection matrix myself rather than using gluPerspective() or glFrustum(). I used the matrix in the back of the red book defined for perspective projection. I’m having trouble coming up with the same values for the matrix I’m calculating that gluPerspective() comes up with. I was hoping someone could spot and see if I’m missing something.

For a camera with aspect ratio 1.33, a viewAngle of 30.0, and clipping planes at 0.1 and 300.0:

gluPersp matrix (from glGetDoublev()):
2.79904
0
0
0
0
3.73205
0
0
0
0
-1.0
-1.0
0
0
-0.2
0

my matrix:
2.79904
0
0
3.73205
0
0
0
0
-1.0
-0.2
0
0
-1.0
0

The 11 and 14 positions seem to be swapped. I’m confused by position 14, as all my references say to load -1.0 here. Why would gluPerspective’s position 14 be anything other than -1.0?

Thanks for any help!

My copy of the Red Book says matrix[11] is -1, and matrix[14] is -2fn/(f-n). Here 's an online version of the 1.2 guide whihc says the same thing.

Ok, maybe you just got the position of the indices the wrong way. If you number them row by row, you get the matrix you got. However, OpenGL number the indices column by column, as shown here .

Doh!

Thanks Bob. I was loading the matrix in row major order (and reading the output of glGetDoublev in row major order as well.)

Everything was doing what it was supposed to. Except me. :slight_smile: