Results 1 to 9 of 9

Thread: Light Problem

  1. #1
    Member Newbie
    Join Date
    Mar 2002
    Location
    Italy
    Posts
    44

    Light Problem

    In my program i load a DXF model, create a directional light and a camera, and move/rotate/translate/scale each of them.
    My problem is that the objects are positioned well, but are lit as if they still were in the origin, and not relative to their real position.

    This is the code of the rendeing part:

    el=list;
    while (el)
    {
    if (!el->specialFlag)
    {
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnable(GL_NORMALIZE);
    glLoadMatrixf(el->matrix);
    glNormalPointer(GL_FLOAT,0,el->normalArray);
    glVertexPointer(3,GL_FLOAT,0,el->vertArray);
    glDrawArrays(el->type,0,(GLsizei)el->vertArrayCur/3);
    }
    el=el->next;
    }

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    glLoadIdentity();
    el=list;
    while (el)
    {
    if (el->specialFlag==POINTLIGHT)
    {
    for (i=0;i<4;i++)
    lightPos[i]=el->lightPos[i];
    multMatrVect(el->matrix,lightPos);
    glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
    }
    el=el->next;
    }

    (el->matrix holds the tranform matrix associated with that element;
    el->specialFlag is 0 for objects, and !=0 for camera and light)

  2. #2
    Member Newbie
    Join Date
    Mar 2002
    Location
    Italy
    Posts
    44

    Re: Light Problem

    mmm, I have the same problem if I move the object and not the light: the illumination doesn't change

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Dec 2007
    Posts
    1,077

    Re: Light Problem

    Remember that light positions are transformed with the MODELVIEW matrix exactly like the rest of geometry. You may need to push/pop the matrix stack for the lights in order to not transform them with the geometry.

  4. #4
    Member Newbie
    Join Date
    Mar 2002
    Location
    Italy
    Posts
    44

    Re: Light Problem

    The problem is when i move the object: the light is not moved, but the object is lit as if it was still in the origin.
    I tried with some glPushMAtrix and glPopMatrix, but it didn't help

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Dec 2007
    Posts
    1,077

    Re: Light Problem

    try this:

    glMatrixMode( GL_MODELVIEW );
    glPushMatrix();
    glLoadIdentity();

    // put the light definitions here

    glPopMatrix();

  6. #6
    Member Newbie
    Join Date
    Mar 2002
    Location
    Italy
    Posts
    44

    Re: Light Problem

    It doesn't work.
    it seems to me that openGL applies the lighting to the object centered in the origin, and then places it in the real position.

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Light Problem

    Are you by chance using a directional light?

    You don't show what values you are using for GL_POSITION, but if you are setting the 4th number in the array to 0 (or worse yet, only have 3 components in the array) you will have a directional light, not a positional light.

    Example:

    float lightpos1[4] = {0.0, 0.0, 1.0, 0.0}; // directional
    float lightpos2[4] = {0.0, 0.0, 1.0, 1.0}; // positional
    Deiussum
    Software Engineer and OpenGL enthusiast

  8. #8
    Member Newbie
    Join Date
    Mar 2002
    Location
    Italy
    Posts
    44

    Re: Light Problem

    YESSSSSS!!!!
    THANK YOU SO MUCH!!!!!
    I'M SOOOO DUMB!!!!
    I tried doing a thousand changes except that fourth parameter which i left to 0.0!
    I didn't understand well the difference between a spot and a directional light
    THANK YOU SO MUCH!

  9. #9
    Senior Member OpenGL Pro
    Join Date
    Dec 2007
    Posts
    1,077

    Re: Light Problem

    Ahhhhhhh, it's always nice to see new error-symptoms nice it's solved now, and sorry for my stupidity.

Similar Threads

  1. Problem with light
    By Srcee in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-02-2011, 06:09 AM
  2. Problem with the light
    By Aquileo in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 12-04-2003, 01:31 AM
  3. Light Problem
    By Stack Overflow in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 01-07-2003, 11:40 AM
  4. Light Problem
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-02-2001, 05:25 AM
  5. Light problem
    By Claudio in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 09-30-2000, 12:15 PM

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