This topic is 4270 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I was just making a terrain loading and rendering problem when I encountered a very annoying and puzzling(for me) problem. When I face down the z axis one direction, the terrain is perfectly lit. When I turn around 180 degrees it is dark. It does not matter where I am for x,y,z coordinates, this always happens. I have some pictures below. Facing one direction: Facing 180 degrees turned around Facing midway between I hope you understand what I mean. Please help me. Thanks.

##### Share on other sites
Where is the light? What direction is it facing? (assuming it's directional) Overall, how have you got your lighting set up? [smile]

I'm assuming you're using fixed function lighting for a start.

It's hard to tell exactly what you mean without seeing it moving. At a guess it's one of 3 things:

3) your light pointing in the direction you face originally, and away from you when you've turned 180.

You should be able to work it out by a process of elimination.

It sounds like the brightness of the terrain is actually changing as you move, rather than just being darker on one side - if so eliminate possibility 3.

You can eliminate possibility 1 by looking at your parameters, or by observing if the brightness changes based on your angle to face normals. Looking again at your shots, I'd say probably not.

So (shirlock holmes hat on) I deduce that it's probably possibility number 2. You'll need to change the order you set the camera and the light position.

Hope that helps

##### Share on other sites
Thanks alot for that. Well, you said something about specular outweighing the difuse, and actually I did not even set diffuse, only specular. Also, I haven't calculated normals on the terrain(i guess that might be the problem). I'm not completely sure about what you mean in 2 and 3 but it seems that one of those could be a problem in my instance.

Here is my light definition arrays:

GLfloat lightdir[] = {0.0,1.0,0.0,1.0};
GLfloat sun[] = {.9,1.0,1.0,1.0};
GLfloat sunamb[] = {.15,.3,.3,1.0};

and the light def:

glEnable(GL_LIGHING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, lightdir);
glLightfv(GL_LIGHT0, GL_AMBIENT, sunamb);
glLightfv(GL_LIGHT0, GL_SPECULAR, sun);

and thats it. I hope that helps. Thanks again.

##### Share on other sites
Ok first off, you need normals for lighting to work, 2nd why would you have specular lighting on terrain?

##### Share on other sites
I used to have the same problem. Heres the solution:

enable light

glRotatef(up_angle, 1, 0, 0);
glRotatef(angle,0,1,0);
glTranslatef(-camera_xpos,-camera_ypos,-camera_zpos);

glRotatef(up_angle, 1, 0, 0);
glRotatef(angle,0,1,0);
glTranslatef(-camera_xpos,-camera_ypos,-camera_zpos);

DrawTerrain();

peace.

if you dont understand why you have to do that, then just repost.

1. 1
2. 2
Rutin
19
3. 3
JoeJ
16
4. 4
5. 5

• 36
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631703
• Total Posts
3001814
×