# Strange lighting problem

## Recommended Posts

For some reason my objects are displaying almost-flat shaded. It doesn't matter where I put the light. It's not the normals (which were exported from max) -- the problem happens even when using a primitive like glutSolidSphere and I know that generates normals. What could be causing this? [img]http://img237.imageshack.us/img237/7010/lightingprobdz3.jpg[/img]

##### Share on other sites
Have you even enabled all the required lighting states? You need to enable both GL_LIGHTING to turn on lighting in general, and the individual GL_LIGHTn aswell.

##### Share on other sites
Yes, I am

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);

There IS lighting happening, and there IS shading happening...it's just not happening correctly.

I'm using the following material params, although, I have tried fussing with all these numbers and I get the same problems regardless of shininess, specularity, ambient, or diffuse lighting amts. The position of the light also does not make any difference. I have tried making the light follow the camera by only setting the lighting param once before the drawing func, or having it move by redrawing it on each frame...but regardless of whether or not I do this, and regardless of the values for light position, the light always seems to come from below, and from the back edges of objects...

GLfloat mat_specular[] = { .2, .2, .2, 1.0 };
GLfloat mat_shininess[] = { 0.5 };
GLfloat light_position[] = { -2.991, -25.599, 52.613 };
GLfloat light_pos_follow[] = { 0,0,0 };
GLfloat light_ambient[] = {0.0, 0.0, 0.0,0};
GLfloat light_diffuse[] = {0.1, 0.1, 0.05, .1};

glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_pos_follow);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);

##### Share on other sites
The jpg encoding made it difficult to understand what was happening, this should be a better image (why doesnt this forum display images?)

One of these might display...

[URL=http://imageshack.us][IMG]http://img98.imageshack.us/img98/3360/light2jw3.png[/IMG][/URL]

http://img98.imageshack.us/img98/3360/light2jw3.png

##### Share on other sites
If you look closely, you will see that some kind of primitive shading is occuring here...

• GLfloat light_position[] = { -2.991, -25.599, 52.613 };GLfloat light_pos_follow[] = { 0,0,0 };

looks a little bit odd to me. The light array should have a size of 4. One component for each axis and a value for describing what type of light opengl is dealing with. If the last parameter is omitted you can't tell if it is a directional light or a point/spot-light. Directional lights are defined by 0, spot and point lights are 1.

Jouvieje OpenGL lighting tutorials

NeHe light tutorial

##### Share on other sites
Are your normal vectors set up properly? It looks like you are either using wrong normal vectors or they are pointing the wrong way. This may be caused by scaling, because the scene gets scaled, but the normal vectors don't. So, if you scale your scenes, you need to scale your normals too. The easiest way to do this is to enable GL_NORMALIZE.

-Riku

##### Share on other sites
Quote:
 The light array should have a size of 4.

Ok. I added another 1 to the end. It didn't change anything.

Quote:
 Are your normal vectors set up properly?

GL_NORMALIZE is already enabled, and I have the same problem if I try to use glutSolidSphere that comes with normals

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627715
• Total Posts
2978782

• 9
• 21
• 14
• 12
• 42