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 7 of 7

Thread: Weird Lighting-Problem

  1. #1
    Intern Contributor
    Join Date
    May 2001
    Location
    Hamburg, Germany
    Posts
    75

    Weird Lighting-Problem

    Hi!
    I have added a light to my scene, but the lighting only works, if the light is located at 0,0,0....if i move my light, my objects just donīt get lit.
    Why?? Shouldnīt the objects just get lit in a diffrent way?? But lighting just seems to be off...Please help!

  2. #2
    Junior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    California, USA
    Posts
    167

    Re: Weird Lighting-Problem

    Make sure you call glLightfv(GL_LIGHT0, GL_POSITION, pos) every frame.

    Old GLman

  3. #3
    Junior Member Newbie
    Join Date
    May 2002
    Posts
    17

    Re: Weird Lighting-Problem

    Post the code where you are using the light for see it.

  4. #4
    Intern Contributor
    Join Date
    May 2001
    Location
    Hamburg, Germany
    Posts
    75

    Re: Weird Lighting-Problem

    Sorry, I canīt post the code...it would be too much and itīs in a lot of diffrent classes and functions etc.
    But my problem even got more weird. When I look around in my scene, sometimes my objects ar lit correctly, but then, when camera has a special angle, the colors get changed and sometimes my whole scene is just drawn in black/white.....also my cursor gets white (before it was black). When I look back itīs black again and the other colors appear correctly

  5. #5
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: Weird Lighting-Problem

    This sounds completely whacked. You have some serious problems that could be the result of many things. Try simplifying things. Check your normals, check your light position values and watch where you apply it (hopefully after view transformation but before model transformation).

    Some of your issues sound like you are positioning the light before the viewing matrix transformation has been loaded onto the modelview stack.

    You need to understand the difference between positioning the light attached to the viewer, positioning the light in the scene and positioning it attached to an object. It all depends on what's on the modelview at the time.

  6. #6
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: Weird Lighting-Problem

    P.S. make sure that you are specifying the correct type of light with the fourth coordinate i.e. point light vs light vector. I assume you want a point source since you specify a position of 0,0,0. So you need to specify a position of 0,0,0,1 where the fourth coordinate w is one not zero. The one means you have a point light vs a directional (distant) light. Specifying a light position of 0,0,0,0 would be a very nasty thing to do and may explain many of your problems.

  7. #7
    Intern Contributor
    Join Date
    May 2001
    Location
    Hamburg, Germany
    Posts
    75

    Re: Weird Lighting-Problem

    Ah!!! That was it!!!!
    I always called:
    Code :
    		GLfloat  lightpos[3];
    		lightpos[0]=light_x;
    		lightpos[1]=light_y;
    		lightpos[2]=light_z;
    		glLightfv(GL_LIGHT0,GL_POSITION,lightpos);
    So i added a fourth coordinate with 1.0f and it works as it should!!! :-)
    Maybe the arrays pointed some weird data...

Posting Permissions

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