Lighting Basics: Adding a Light Source to Your Scene in OpenGL

Zerihun M.
3 min readAug 27, 2024

Hey there! In this guide, we’re going to dive into the world of lighting in OpenGL. Just like in real life, light is essential in a 3D scene to make objects look more realistic. In this tutorial, we’ll learn how to add a simple light source to your scene.

Why is Lighting Important?

Imagine you’re in a dark room with no light. You wouldn’t be able to see anything, right? The same idea applies to 3D scenes. Without light, everything would look flat and lifeless. Lighting helps to show details, create shadows, and give depth to your objects.

Types of Lights in OpenGL

In OpenGL, there are several types of lights you can use:

  • Ambient Light: This is the background light that spreads out evenly across the scene.
  • Diffuse Light: This light comes from a specific direction, like sunlight.
  • Specular Light: This light creates shiny spots on objects, like the reflection of the sun on a shiny car.

In this post, we’ll focus on adding a simple directional light to our scene.

Setting Up Lighting in OpenGL

Let’s get started by adding some basic lighting to a 3D object, like a cube.

1. Initialize Lighting

--

--

Zerihun M.

OpenGL expert sharing insights and tutorials on basic and advanced graphics programming and development techniques.