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.


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



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.

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

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).]

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.

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!

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.

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!


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.

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.


Okay… so polygon winding makes a difference with respect to lighting effects, or so I’ve learned. I was under the impression that if I use GL_FRONT_AND_BACK for evertthing, it would still work (although slower). I guess not! I’ve gotten most things to work fairly well now.

But I’m sure more questions will follow…


I’m pretty sure that winding is not going to matter for opengl lighting. Humm. What lead you to this conclusion?

Well, polygon winding seemed to make some sort of difference, as only a few of the faces of the cube were lit (normals and all specified) as I had started. Then I went back through, keying on culled faces to turn around the faces that weren’t facing outwards. After I did that, all the sides were lit. Imagine that.

And as said before, this seems kinda stupid here, because (unless it means something other than it obviously states) for all the lighting options I was using GL_FRONT_AND_BACK, including using the two-sided option.

Go fig. Anyways, lighting, textures, etc are all working for me. By the way, anyone need a fairly generic MFC OpenGL window class?