EAGL.Examples.LearnOpenGL.Lighting.Colors (eagl v0.9.0)
View SourceLearnOpenGL 2.1 - Colors
This example introduces the fundamental concepts of lighting in OpenGL by demonstrating how colors interact with light sources. It renders a coral-coloured cube illuminated by a white light source, showing the basic principle of colour reflection.
Original C++ Source
This example is based on the original LearnOpenGL C++ tutorial: https://learnopengl.com/code_viewer_gh.php?code=src/2.lighting/1.colors/colors.cpp
Framework Adaptation Notes
This example demonstrates:
- Basic lighting setup with object and light source
- Colour multiplication for simple lighting effects
- Dual shader programs for different object types
- Foundation concepts for more advanced lighting models
Key Learning Points
- Colour Theory: How light colour affects object appearance
- Shader Organisation: Using multiple shader programs in one scene
- Light Source Visualisation: Rendering the light position as a visible object
- Basic Lighting Math: Colour multiplication as light reflection
Lighting Concepts
Colour Reflection
When light hits an object, the object absorbs some colours and reflects others. The colour we perceive is the combination of the light colour and the object's material properties.
Mathematical Representation
result_colour = light_colour * object_colour
For example:
- White light (1.0, 1.0, 1.0) × Coral object (1.0, 0.5, 0.31) = (1.0, 0.5, 0.31)
- Green light (0.0, 1.0, 0.0) × Coral object (1.0, 0.5, 0.31) = (0.0, 0.5, 0.0)
Visual Effect
The scene shows:
- A coral-coloured cube at the origin (object being lit)
- A small white cube representing the light source position
- Basic colour interaction demonstrating light reflection principles
Controls
- W/A/S/D: Move camera forward/left/backward/right
- Mouse Movement: Look around (first-person view)
- Scroll Wheel: Zoom in/out (field of view)
- ENTER: Exit
Usage
EAGL.Examples.LearnOpenGL.Lighting.Colors.run_example()
Press ENTER to exit.