material lighting not working correctly

This is driving me crazy! I set all materials to black and it still lights the model! Why does it do this??? I don’t have any ambient light. I only have diffuse.

Here is some code:

void PositionLights(void)
{

GLfloat 	gLightPosition[] = {0.0f, 0.0f, 1.0f, 1.0f};
float		globalAmbient[] = {0.f, 0.f, 0.f, 1.0f};
float		ambient[] = {0.f, 0.f, 0.f, 1.0f};
float		diffuse[] = {1.f, 1.f, 1.f, 1.0f};
float		specular[] = {0.f, 0.f, 0.f, 1.0f};

//glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalAmbient);

//setup the one directional light
glLightfv(GL_LIGHT0, GL_POSITION, gLightPosition);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular);

    // draw a sphere where the light is
glDisable(GL_LIGHTING);
glColor3f(0.75f, 0.75f, 0.0f);

glPushMatrix();

	glTranslatef(gLightPosition[0], gLightPosition[1], gLightPosition[2]);
	glutWireSphere(0.5, 24, 24);

glPopMatrix();

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

}

And in the drawing…

				// set the material ambient color
			

				materialColor[0] = 0.0f;
materialColor[1] = 0.0f;
materialColor[2] = 0.0f;
materialColor[3] = 1.0f;
				glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, materialColor);

				// set the material diffuse color
					materialColor[0] = 0.0f;
materialColor[1] = 0.0f;
materialColor[2] = 0.0f;
materialColor[3] = 1.0f;
				glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, materialColor);

				
				// set the material specular color
			
				materialColor[0] = 0.0f;
materialColor[1] = 0.0f;
materialColor[2] = 0.0f;
materialColor[3] = 1.0f;
				glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, materialColor);
				
				// set the material shininess factor
				float shininess;
shininess = 0.0f;
				glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &shininess);

					glEnable(GL_TEXTURE_2D);
					glEnableClientState(GL_TEXTURE_COORD_ARRAY);
					glEnable(GL_COLOR_MATERIAL);

					// set the texture id we stored in the map user data
					
					CBitmapInfo* pBitmapInfo = (CBitmapInfo*) pCalRenderer->getMapUserData(0);

					if (pBitmapInfo != NULL)
					{
					
						glBindTexture(GL_TEXTURE_2D, pBitmapInfo->GetId() );

					}

					// set the texture coordinate buffer
					glTexCoordPointer(2, GL_FLOAT, 0, &meshTextureCoordinates[0][0]);
					glColor3f(1.0f, 1.0f, 1.0f);

…Then I go on to draw the polygons

But why is my model even being lit at all?

Thanks in advance!

You disable lighting before you draw the wireteapot. try putting glEnable(GL_LIGHTING) and glEnable(GL_LIGHT0) before the glPushMatrix();

Actually, that wireframe sphere is supposed to have lighting disabled. It represents the light position.

The problem happens down at the bottom of the code where I draw the polygons for the model. It seems to me that it should not be lit at all because all of the materials are 0.0f

But, it is still being lit for some reason.

With GL_COLOR_MATERIAL enabled, OpenGL gets the material color (or a portion thereof) from the current color, not from the material.

[This message has been edited by DFrey (edited 01-27-2003).]

Yes, that was it. Thanks DFrey!