Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: How to draw a frustrum from a given position

  1. #1
    Intern Newbie
    Join Date
    Aug 2008

    How to draw a frustrum from a given position


    i'm doing projective texture mapping. I want to visualise the projection that I'm using - i.e draw say a pyramid with the top at the light position and the rest aligned with the projection (frustrum) i'm using.

    I would like to use the terms given to glFrustrum = i.e a top, bottom, left right, near and far.

    I know glFrustrum calculates a matrix in eye space, and I would initially create my pyramid according to these coordinates. How can I take this pyramid and transform it to the light position?

    I have a modelview matrix for the light, which allows me to render from that position. I'm not sure how to go from this to a transform that I can actually apply to my "pyramid" though.

    Thanks for any help>!

    EDIT: I know how to do construct this using vectors (i have a light direction) but would like to know how to do this by transforming a given set of vertices in eye space. cheers!

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Montreal, Canada

    Re: How to draw a frustrum from a given position

    There is a demo at

    "Simple Soft Shadows"

    which draws the frustum as a pyramid.
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  3. #3
    Intern Newbie
    Join Date
    Aug 2008

    Re: How to draw a frustrum from a given position

    Hmm I don't see it..(the frustrum)
    - There are a couple of other shadow mapping examples there, it may be one of those (Hardware Shadow Mapping looks promising)

  4. #4
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006

    Re: How to draw a frustrum from a given position

    Assuming you have the direction from light to the scene, lets call it lz and the camera vertical direction (from light point of view) is world Y.

    You can compute basis vectors in light space: (lx,ly,lz) expressed in world space like this:

    lx = normalize(cross(Y,lz)); // cross is cross product
    ly = normalize(cross(lz,lx);
    lz = lz

    I am not sure about the vector order inside cross product, I let you verify this.

    Then, you move along the lz axis until the near plane and move along lx and ly to left, right, up (the glFrustum arguments) and down to find the pyramide points coordinates (on the near plane).

    Finally you can easily find the view volume points on the far plane which lengthens vectors from light to points on the near plane.

    Hoping this is clear enough (sorry, I don't have time to draw a figure).

Posting Permissions

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