Jump to content
  • Advertisement
Sign in to follow this  
Darobat

Lighting Isn't Working (solved)

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.
// 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);


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]

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
If I negate the normals it is still dark.
	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.

Share this post


Link to post
Share on other sites
Yes... The terrain is dark. If I don't call enable lighting everything is visible but obviously there is no lighting.

Share this post


Link to post
Share on other sites
LMFAO! I'm kicking myselft now. When I set the ID for the light, I set it with
_id = _id;
rather than
id = _id;
So I was esentailly giving the light no ID. It works now.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!