Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Lighting Question

  1. #1
    Member Regular Contributor
    Join Date
    May 2000
    Location
    Batavia, NY, 14020
    Posts
    259

    Lighting Question

    Howdy... I'm wrasseling with one greased piggy of an OpenGL problem here...

    Okay, maybe not, but I've been fighting with this since I started playing with the API many moons ago, so HELP ME!!!!!!!!!!!! Hehe, sorry bout that.

    Anyways, I have not been able to get lighting to work properly for myself, ever. Whats the secret?

    So my problem is that - anything - but for this case, say just a simple cube... I can define a stationary lightsource, but as I rotate the object, only certain faces get lit. Say the lightsource is directly in front of the object, pointing along the z-axis... I only get specular flashes on maybe 3 faces as the cube rotates. I've defined normals, but they don't really help any (unless I'm doing it wrong). Oh yeah, the same thing happens with ambient and diffuse lightsources as well. As the object rotates, the lighting seems to get "de-applied" to the face.

    HELP ME!!!!!!!!!

    Oh, while you're at it, tell me why I can't get textures to work either...

    Thanks

    Siwko
    - I am not opensource! -

  2. #2
    Guest

    Re: Lighting Question

    You REALLY need to define normals, and define them correctly. Normals are everything in lighting. Note that if you scale your model non-uniformly, you may have to re-scale and re-normalize your normals, too, as OGL doesn't do it for you.

  3. #3

    Re: Lighting Question

    Yeah, if you don't unify your normals, your graphics card will have to do it itself (according to that official ogl book)

  4. #4
    Intern Contributor
    Join Date
    Jun 2000
    Location
    Rostov-on-Don,Russia
    Posts
    51

    Re: Lighting Question

    And only if GL_NORMALIZE is enabled ( which slows down the things ) or GL_RESCALE_NORMAL_EXT ( part of GL_EXT_rescale_normal, a bit faster but is good only for uniformed constant scale ).

    [This message has been edited by onyXMaster (edited 07-22-2000).]
    Aristarkh Zagorodnikov aka onyXMaster
    ICQ 36987938

  5. #5
    Junior Member Regular Contributor
    Join Date
    Apr 2000
    Posts
    116

    Re: Lighting Question

    First make sure you're normals are right since that is most likely you're problem. However another place that might be causing problems is that you are rotating you're light with you're scene when you think you aren't or you aren't rotating it when you think you are. So just make sure you're rotating and translating you're light like you think you are. I had this problem with cubes and it turned out to be how I was moving the light. Using spheres makes it easier to track down this kind of a problem.

  6. #6
    Member Regular Contributor
    Join Date
    May 2000
    Location
    Batavia, NY, 14020
    Posts
    259

    Re: Lighting Question

    Well, I'm fairly certain that the light isn't moving anymore, but the effect is still there...

    As far as normals go, am I supposed to define surface normals or vertex normals? It'll be a pain in the butt if I have to define a normal for every vertex (how in the world do you do that anyways?).

    Anyhow, I'm just trying to write up a generic MFC engine that works, and this is pissing me off!
    - I am not opensource! -

  7. #7
    Junior Member Regular Contributor
    Join Date
    Apr 2000
    Posts
    116

    Re: Lighting Question

    For normals all you have to do is make a glNormal3f() call and that is the normal that gets assigned to every vertex there after. Until you call glNOrmal again.

  8. #8
    Member Regular Contributor
    Join Date
    May 2000
    Location
    Batavia, NY, 14020
    Posts
    259

    Re: Lighting Question

    Okay, so I do that... but that doesn't explain the "flashing" lights I've run into. What happens is that when the cube rotates (the cube that I'm using as a test object), the specular lighting effect that I have set up directly in front of the cube (some 20 units away or so, I think infinite distance) turns on and off as the cube rotates.

    To be more specific, as the cube rotates, if a corner vertex set (3 vertices) isn't ... well ... isn't rotated towards the eye within a certain arc, like from the eye maybe 60degrees left or right, then there is no lighting effect. Otherwise, the effect shows and stays relatively stationary, focused on the corner vertex set.

    Would it be the case that even on a cube, I must finely tessolate the faces in order to achieve a smoothly moving object with the effect reflecting off the face properly?

    All I can say is that OpenGL is really bothersome when it comes to lighting!

    Siwko
    - I am not opensource! -

  9. #9
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,757

    Re: Lighting Question

    How fine is the tesselation of each face? If each face is just 2 triangles, then that could be the source of the flashing. Try using 18 triangles per face and see if the flashing subsides.

  10. #10
    Member Regular Contributor
    Join Date
    May 2000
    Location
    Batavia, NY, 14020
    Posts
    259

    Re: Lighting Question

    Thats what I was thinking as well. Technically, a face is composed of one polygon (Using GL_QUADS for each face), but I think the default for a GL_QUAD is 2 triangles, correct?

    Anyways, thats gotta be pretty damn annoying to have to "construct" a highly tessolated square just to get decent lighting effects.

    No ways around it I assume?

    Anyways, I may post up some code and/or the demo-app to see if anyone wants to help me later on today.

    Please, if there's any other suggestions, tips, articles, links, etc that would help or be pertinant here, send them my way. I'd like to get to the bottom of lighting before I move on to textures.

    By the way, most demos I've seen don't explain too much to me, as they "seem" to do the same thing I am, except that they work.

    Siwko
    - I am not opensource! -

Posting Permissions

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