Advertisement Jump to content
Sign in to follow this  

3D Lighting Problem

This topic is 4891 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

Hello, I am using OpenGL, but thought to post this in the general game programming forum as I am sure a similar problem could happen in D3D. I seem to be having trouble with lighting in my current project which creates terrain from a heightmap. The problem seems to be with directional lights. When I set up a directional light, the entire world is lit as if I was only using ambient light, so I am getting a 2d looking landscape basically, because there is no shading done along the hills or anything. However, when I use a positional light, things seem to work correctly as the 3d terrain appears to be correctly lit along the hills and valleys and such. I am simply using:
float[] diffuseLight = {0.5f, 0.5f, 0.5f, 1.0f};
float[] lightPos    = {0.0f, 1.0f, 0.0f, 0.0f};
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);

I am fairly sure my normals are calculated correctly else the positional light wouldn't work I am assuming. Does anyone know what is wrong? Am I setting up the directional light incorrectly? Thanks in advance.

Share this post

Link to post
Share on other sites
did you enable lighting via glEnable(GL_LIGHTING) ??

I think you have to enable every light seperatley too, so you'd have to enable GL_LIGHT0 or something. I'm gonna get some old code, and report back.


Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!