Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Simple light problems

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

I'm new to OpenGL so my questions can be silly, but I can't find answers by google.

I have simple scene: one blue quad and one light source.

1. When light is in front of quad, quad is light blue. When light is behind quad, quad is dark blue. But, when surface is not lighted, I want it to turn black. How to achieve that?

2. When light is in front of quad it have the same color no mater if light is close to quad or far away from quad. Is it easy way to implement going lighter or darker when light source cones closer of more far away?

Share this post

Link to post
Share on other sites
To fix the first issue, I think that you should either implement shadows (hard and expensive) or enable faces with both normals (it's called two sided lighting or so)

For the second one, its called attenuation, and you can use it with for example:


Anyways, you should start researching in shaders (GLSL), as you can make a much higher quality light (built in pipeline lights are per-vertex and CPU intensive), and also cool effects...


Share this post

Link to post
Share on other sites
1. You need to set the ambient light to zero:


Glfloat global_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);

Per lightsource:

GLfloat ambient[] = { 0.0f, 0.0f, 0.0f };
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);

Edit: per Material:

Set the ambient property/color of the assigned material to 0.

End Edit.

2. How do you specify light direction?

Note that if the 4th component is 0 the light is treated as a directional light and thus distance doesn't matter.

For more information, have a look here.

Later you should go into shaders, but for a starter check the default light model.

Share this post

Link to post
Share on other sites
Thanks for response :)
This OpenGL is for simple university project, so I don't think I will have time to learn how to do shadows.

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!