Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: gluPerspective question

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2004
    Location
    Playa del Rey, CA, USA
    Posts
    17

    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!

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    3,115

    Re: gluPerspective question

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

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    3,115

    Re: gluPerspective question

    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 .

  4. #4
    Junior Member Newbie
    Join Date
    Jan 2004
    Location
    Playa del Rey, CA, USA
    Posts
    17

    Re: gluPerspective question

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •