Light on wrong faces

First of all, excuse my bad english. Usually I talk and write in german…

I’ve got a light and some 3d objects like 3-dimensional ellipsis, on which I calculate the normals myself. The problem is, that the faces looking to the light are dark and the ones on the other side are lighten…
Are there some completely wrong initialisations?
Also, when I move the light the lighten faces keep looking the same.

If the object is lit on the wrong side, it’s probably your normals that are pointing in the wrong direction.

The other problems seems somewhat more strange. Maybe you aren’t updating your scene? Are you doing any transformations to the projection matrix?

thanks for reply,

but among the objects is a sphere, created with “gluSphere”, which has got the same “symptoms”. Could this “thing” appear with wrong light initialisations?

The other issue works now, the light moves.


Here is the code fragment for the light.
CGLLight::Render() is called by the main
render function. I enable the light each time to be sure they work if they are disabled somewhere else.

CGLLight::CGLLight(GLenum pname, float *params)
m_ltname = pname;
for (int i=0;i<4;i++)
m_params[i] = params[i];

m_lnumber = s_lnumber;	

m_Diffuse[0] = 0.5f;
m_Diffuse[1] = 0.5f;
m_Diffuse[2] = 0.5f;
m_Diffuse[3] = 1.0f;

m_Specular[0] = 1.0f;
m_Specular[1] = 1.0f;
m_Specular[2] = 1.0f;
m_Specular[3] = 1.0f;


void CGLLight::Render()


	glLightfv(GL_LIGHT0+m_lnumber, GL_DIFFUSE, m_Diffuse);
	glLightfv(GL_LIGHT0+m_lnumber, GL_SPECULAR, m_Specular);


Are you sure the wrong faces are lit? Maybe the light source is just on the other side (happened to me once). For having e.g. the object rotate and the light source stay in one place, set the light position after you change the modelview matrix.

How are you creating your object? In code or import from a 3D application? Both could be reasons for messed up normals.

Bis die Tage

hmmm, for what it’s worth, what I usually do, especially with more than one light, is draw big red Quads at the lights position. I make sure the quad and the light has the same coordinates at all time. Hereby you can always see exactly where the light is. Also, I had it happen more than once, and every time I want to kick myself in the nuts. The function that calculates youre normals…is that 100% correct. Sometimes I make a small mistake and the normals are technically speaking, inverted. Which causes crap as you can imagine.

thanks for reply

I’ve got an object, which I calculate in my application, but I’ve got another object created with “gluSphere” which should have correct normals (The Sphere is inside my object). But both objects are lit the same wrong way (The light is outside).
I draw a line from the origin to my lightposition, but where the light should illuminate the object, everything is dark. Where it should be dark, the light “works”.

But when I remove the line with “glLightfv(GL_LIGHT0+m_lnumber,m_ltname,m_params);” (m_ltname = GL_POSITION) the lightning is calculated correctly. But this way I can’t move the light around…

Hehehe, man thats a kak one.
I don’t think I know the answer.
Maybe ask one of the more advanced dudes, in advanced section??
Good luck.

thanks anyway, RedZen, Dodger and Bob

That suggests that you changing the type of light it is. Remember for lights, if w=0, then the light is a directional light, otherwise it is a positional light. I suspect your m_params is incorrect.

Also this may be stating the obvious but it looks like there is a syntax error in your code as posted. Now obviously that error is not in your code else it wouldn’t compile.

Also, I personally, would not put the glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE) call in the light class since material is a primitive’s property and not a light’s property.

Also, if this class is going to be used with real-time animation, you should cache a local copy of the important GL state variables, and only call into OpenGL when a state is changed, to prevent calling into OpenGL’s state change code unecessarily.

I’ll do performance tuning, when I removed this …

The debugger says that the w param of m_params is 1. So it should be a pointlight. After several starts I get a “Access Violation Error in G200ICD.DLL” (My graphics is a Matrox Millenium G200 ). Maybe a corrupt driver? But i don’t think so…

Is there any OpenGL-initialisation who would turn things this way? Take the normals as their opposite or something?

Ok Ok Ok…
all my fault.
I thought that the gluSphere would calculate the normals right by itself, but that’s wrong. I had the wrong “gluQuadricOrientation”-statement. So both normals (sphere and ellipsis) were wrong. So stupid!

So, thanks for your replys!