Lighting prolem - did I miss anything?

Started by
4 comments, last by Lord_Evil 14 years, 2 months ago
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.
Advertisement
What are your lighting values?
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
  LightAmbient[1] := 0.5;  LightAmbient[2] := 0.5;  LightAmbient[3] := 0.5;  LightAmbient[4] := 1.0;  LightDiffuse[1] := 1.0;  LightDiffuse[2] := 1.0;  LightDiffuse[3] := 1.0;  LightDiffuse[4] := 1.0;  LightPosition[1] := 2.0;  LightPosition[2] := 2.0;  LightPosition[3] := 0.0;  LightPosition[4] := 1.0;  mcolor[1] := 1.0;  mcolor[2] := 0.0;  mcolor[3] := 0.0;  mcolor[4] := 1.0;


My lighing values (as shown above) are dark gray for the ambient lighting, white for the diffuse color and the test quad itself is red (mcolor). The position of the light source is little bit to the right and above my quad.
Have you played around with the attenuation values? Maybe your light isn't 'reaching' your vertices. Have you tried using a directional light instead of a point light?
Yes, I tried it, but I saw no effects. Does anyone here use OpenGL in combination with Delphi?

Normally, I program with C++ and OpenGL, but I have to do this project for the company I am working for and so I have to use Delphi. I've heard that Delphi's own OpenGL module isn't that good, but is it really that bad, that it's not aible to handle diffuse lighting? I know, that there is a good Delphi OpenGL library from the delphigl community , but I can't use it, because of its terrible licence (I can't publish the source code of my project, when the product is commercial...).

I programmed the two functions I showed in my first post to check, whether I can use lighting with OpenGL in Delphi. I am pensive at the moment, whether I can use it in Delphi..

What's the value of MAX_SCALE?
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!

This topic is closed to new replies.

Advertisement