Okey, I’m fairly new to openGL but not to programming but now I’m faced with an issue that I cannot get a grip on.
I created a stationary light after which I draw a simple plain flat surface. The light is in front of the surface and I’m looking right at the surface with the light in between me and the surface.
Now the problem is that the further I position the light away from the object the brighter the object gets illuminated. And when the light is almost in front of the plane it’s completely dark.
I have no idea what the problem is with my lighting setup.
Including below a part of my source. This is a snippet from the paint function.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glPushMatrix( );
glRotatef(360.0f - rotX, 1.0f, 0.0f, 0.0f);
glRotatef(360.0f - rotY, 0.0f, 1.0f, 0.0f);
glTranslatef(-posX, -posY, -posZ);
GLfloat light1_position [] = {posTest, 50, 50, 1}; // Static light
GLfloat light1_diffuse [] = { 1.0, 1.0, 1.0, 1.0 };
glLightfv ( GL_LIGHT1, GL_POSITION, light1_position );
glLightfv ( GL_LIGHT1, GL_DIFFUSE, light1_diffuse );
glEnable(GL_LIGHT1);
GLfloat diff [] = { 0.7f , 0.5f , 0.0f, 1.0f };
glMaterialfv ( GL_FRONT, GL_DIFFUSE, diff );
glBegin(GL_QUADS);
glNormal3f(1.0, 0.0, 0.0); //Back
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 100.0, 0.0);
glVertex3f(0.0, 100.0, 100.0);
glVertex3d(0.0, 0.0, 100.0);
/*glNormal3f(-1.0, 0.0, 0.0); // Front
glVertex3f(100.0, 0.0, 0.0);
glVertex3f(100.0, 0.0, 100.0);
glVertex3f(100.0, 100.0, 100.0);
glVertex3f(100.0, 100.0, 0.0);
glNormal3f(0.0, -1.0, 0.0); // Top
glVertex3f(0.0, 100.0, 100.0);
glVertex3f(100.0, 100.0, 100.0);
glVertex3f(100.0, 100.0, 0.0);
glVertex3f(0.0, 100.0, 0.0);
glNormal3f(0.0, 1.0, 0.0); // Bottom
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 0.0, 100.0);
glVertex3f(100.0, 0.0, 100.0);
glVertex3f(100.0, 0.0, 0.0);
glNormal3f(0.0, 0.0, -1.0); // Left
glVertex3f(0.0, 0.0, 100.0);
glVertex3f(0.0, 100.0, 100.0);
glVertex3f(100.0, 100.0, 100.0);
glVertex3f(100.0, 0.0, 100.0);
glNormal3f(0.0, 0.0, 1.0); // Right
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 100.0, 0.0);
glVertex3f(100.0, 100.0, 0.0);
glVertex3f(100.0, 0.0, 0.0);*/
glEnd();