Results 1 to 2 of 2

Thread: Infinite positional lights

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2002

    Infinite positional lights

    I'm trying to get an infinite light source to work correctly. The program is a solar system simulator. Rather than use a point light, I have to use an infinite light for sunlight. The reasons are long... I'll explain them if necessary, but it has to do with scaling the planets to keep them within a reasonable z-range.

    Now, in order to use an infinite light source for the sun, I have to change it's direction for every object I render so that the light appears to be coming from the sun no matter where the planet is in relation to it.

    To do this, I get the vector from the sun to the planet, normalize it, and set that as the infinite light's direction vector just before rendering the planet.

    My problem here is that the light direction always ends up rotated 90 degrees from where it should be. The obvious thing would be that I'm setting the light's position after the object's modelview matrix, but I'm not.

    I essentially do this before rendering each planet:

    glMatrixMode (GL_MODELVIEW);
    glPushMatrix ();
    glLoadMatrixf (m_WorldMatrix.el);
    glTranslatef (0.0f, 0.0f, 0.0f);

    // m_WorldMatrix is the model matrix right after the initial camera transform is set at the beginning of the frame

    ... calc light direction here

    glLightf (GL_LIGHT_0, GL_POSITION, fLightPos);

    glPopMatrix ();

    ... render the planet with lighting enabled.

    I'm apparently just setting up the transformation matrix incorrectly, but I'm not sure how.

    Note that when I was using position lights, everything looked fine except that the light position was too close to the planet and therefore the rays weren't even close to parallel (this short distance is a result of scaling and translating the planets to keep them inside of the z-buffer range).


  2. #2

    Re: Infinite positional lights

    Hmm.. I thought OpenGL post-multiplies matrices with every subsequent transformation, so the last operation performed in the code ends up being the first one geometrically... try changing the order of your operations somehow.

Similar Threads

  1. Positional light help
    By GamerYZ in forum OpenGL: GLSL
    Replies: 5
    Last Post: 05-22-2006, 10:40 AM
  2. directional works, positional fails?
    By jmg in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-01-2002, 05:55 AM
  3. positional light doesnt work right
    By V-man in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 05-31-2002, 12:52 PM
  4. positional light
    By hoshi55 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 06-13-2001, 05:25 AM
  5. Positional Light Attenuation w/ voodoo?
    By JMaynard in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 06-14-2000, 04:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean