Dear forum members,
I am currently developing an OpenGL application and I got stuck at the lighting of my scene. I am not new to OpenGL, but I really don't find my mistake? It would be very nice, if anyone can tell me, whether I missed something. At the moment I can't see the wood for the trees.
Init:
procedure Unit.Init;
const
pfd : TPIXELFORMATDESCRIPTOR = (
// not shown here
);
var
C : TColor;
R, G, B : double;
ratio : double;
begin
// .. some delphi parts are not shown here ..
// viewing projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
ratio := 1.0; // TODO
gluPerspective(45.0, ratio, 0.1, 100.0);
glMatrixMode(GL_MODELVIEW);
glShadeModel(GL_SMOOTH);
glClearColor(R, G, B, 1.0);
glClearDepth(1.0);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
// .. setting the lighting values (not shown here) ..
end;
Draw
procedure Unit.Draw;
begin
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glLoadIdentity;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, @mcolor);
glFrontFace(GL_CCW);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_AMBIENT, @LightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, @LightDiffuse);
glLightfv(GL_LIGHT0, GL_POSITION, @LightPosition);
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_QUADS);
glNormal3f(0.0, 1.0, 0.0);
glVertex3f(-MAX_SCALE, -1.0, -MAX_SCALE);
glVertex3f(-MAX_SCALE, -1.0, MAX_SCALE);
glVertex3f(MAX_SCALE, -1.0, MAX_SCALE);
glVertex3f(MAX_SCALE, -1.0, -MAX_SCALE);
glEnd;
glDisable(GL_LIGHTING);
SwapBuffers(wglGetCurrentDC);
end;
The quad is drawn and the ambient color (dark red) ist shown, but he diffuse color is not visible, i.e. I can move the light source without any illumination changes. The quad stays dark red.
I would be very happy, if anyone of you can help me. I think the problem is really easy, but as I said: I don't see the wood for the trees.