Diffuse lighting not yeilding correct result?

I have a very simple scene,

  • One flat polygon coloured dark blue - glColor3f(0.2f,0.2f,0.5f);
  • One point light in front of the polygon (but not very close)

Both material and light have a diffuse component of (0.1f, 0.1f, 0.1f) - everything else is set to 0.0.

GL_LIGHTING and GL_COLOR_MATERIAL are enabled, shade model is set to GL_SMOOTH.

So why oh why oh why is my polygon WHITE???

btw if I move the light so it is to the left (or right, etc) of the polygon the polygon will then shade the right blue. (Not that I expected that either, I would have expected it to be a much darker blue too).

Can anyone help?

everything else is set to 0.0
Are you sure?
Sounds like a specular lighting effect. Check the normal vector and the specular settings.

Pritty sure… I do after all do this…

    GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 };
    GLfloat no_shininess[] = { 0.0 };

    glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, no_mat);
    glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
    glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);

and…

	GLfloat LightDiffuse[]=	{ 0.1f, 0.1f, 0.1f, 1.0f };
	glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);		// Setup The Diffuse Light

If I swap GL_DIFFUSE for GL_AMBIENT I get the results I would expect for ambient light…

Unless there is something I have missed…

Are you sure you’re looking to the right side of the polygon?
Perhaps try GL_FRONT_AND_BACK instead of GL_FRONT. :confused:

Trying GL_FRONT_AND_BACK made no difference.

ok, and if you say “GL_COLOR_MATERIAL is enabled”, do you mean you have only glEnable(GL_COLOR_MATERIAL) or do you have also glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE) f.e. :wink: ? (Even though this should be the default values)

Originally I only had glEnable(GL_COLOR_MATERIAL) but adding glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE) made no difference to the scene.

By the way, if you enable color material with ambient and diffuse, the values you set with glMaterial have no effect.
The color you set before drawing the polygon is then your ambient and diffuse color.

And be careful to avoid pitfall #14:
http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/
It’s important WHEN you enable color material.
As an OpenGL rule of thumb, always set things first, then enable!

Pitfall #14 has been avoided, I am using AMBIENT_AND_DIFFUSE material, I have ensured the light ambient is off. My colour is glColor3f(0.2f,0.2f,0.5f); therefore (if I read the instructions correctly) the materials ambeint and diffuse properties should be the same. With the lights diffuse at (0.1, 0.1, 0.1) the resulting colour should be (roughly) (0.02, 0.02, 0.05) for the final diffuse property. (with everything else “off” in one way or another I would expect the vetex colour to be (0.02, 0.02, 0.05) - am I being stupid?)

hmmm…perhaps it would be useful if you could post more code, f.e. how your polygon looks like (vertices and normals) and where your light is exactly placed.

Ok, I’ve found what it is.

There’s a glScale hiding in my code which I had forgotten I’d put in there and only just noticed, so of course it was messing up my normals. Just enabled GL_NORMALIZE and I am getting results more along the lines I expected.