// CALCULATE THE NORMAL FOR THE SURFACE
// Bottom Right
p1.Set((startX + x + 1) * scale, vertices[(y + 1) * width + x + 1] * yScale,
(startY + y + 1) * scale);
// Top Right
p2.Set((startX + x + 1) * scale, vertices[y * width + x + 1] * yScale,
(startY + y )* scale);
// Bottom left
p3.Set((startX + x) * scale, vertices[(y + 1) * width + x] * yScale,
(startY + y + 1) * scale);
v1 = p2 - p1;
v2 = p3 - p1;
normal = v1.CrossProudct(v2);
normal.Normalize();
glNormal3f(normal.x, normal.y, normal.z);
Lighting Isn't Working (solved)
Greetings
I am working on my heightmapper(again) and right now when I enable lighting, I get a really dark terrain. You can see the terrain but it is almost completly black. If I turn off the lighting I can see it again.
Thats What I use to calculate the normal for each triangle. I have another topic in the math forum if you wish to see the code for my vector functions. The light source should be right in front of the camera. but it doesnt show up very strong. If this isn't the problem, I'll post the code for my light class.
[Edited by - Darobat on January 2, 2005 1:39:05 PM]
Try negating the x, y and z when you call glNormal(). If that makes it all bright, then you wind your cross product the wrong way around, and get a vector pointing down.
Other things that could go wrong include not specifying the light colors right; specifying too much attenuation when not using a directional light; specifying the material colors wrong, etc.
Other things that could go wrong include not specifying the light colors right; specifying too much attenuation when not using a directional light; specifying the material colors wrong, etc.
If I negate the normals it is still dark.
Thats How I turn on the lighting. The functions pretty much do exactly what is there. CLight::SetPosition() sets a float[4] with the vars passed to it and then calls glLightfv(). ID just sets a var with the lights ID. CLight::Enable() just turns on lighting and enables id.
light.SetID(GL_LIGHT0); light.SetPosition(2.0f, 3.0f, 2.0f, 1.0f); light.SetAmbient(1.0f, 1.0f, 1.0f, 1.0f); light.SetDiffuse(1.0f, 1.0f, 1.0f, 1.0f); light.Enable();
Thats How I turn on the lighting. The functions pretty much do exactly what is there. CLight::SetPosition() sets a float[4] with the vars passed to it and then calls glLightfv(). ID just sets a var with the lights ID. CLight::Enable() just turns on lighting and enables id.
Yes... The terrain is dark. If I don't call enable lighting everything is visible but obviously there is no lighting.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement