Download presentation
Presentation is loading. Please wait.
Published byPenelope Malone Modified over 8 years ago
1
Lecture 6 Lighting
2
Introduction What is light? How do we percept colors? Lights in OpenGL
3
Different Types of Light Ambient Diffuse Specular
4
Defining Lights in OpenGL Defining Light Source Defining Material Defining Light Model Note: glColor will NOT work when using light in OpenGL
5
Light Source Light sources are: –Directional: Source resides in infinity Light rays are parallel Example: Sun. –Positional Source resides in local scene It radiates all directions by default unless restricted by defining a spot light Example: Desk lamp
6
Defining Light Source
7
Adding Light Source void glLightv(GLenum light, GLenum pname, TYPE *param); Example: GLfloat light_ambient[] = { 0.0, 0.0, 1.0, 1.0}; glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
8
Enabling Light glEnable(GL_LIGHTING) glEnable(Light Source) –Eight light source (0-7) Specifying shade model –glShadeModel(GL_SMOOTH)
9
Be Aware of Defaults When lighting is enabled, all the default values for all lights are loaded as shown in the table, unless you cancel them. Use lights other than light0 if you want them to be cancelled by default. Lights [1-7] have most of their default RGB values black.
10
Pitfall When you use translate/rotate, it applies to light direction and position as well. Solution: Use push/pop matrix if you don’t want your light sources to be affected.
11
Light Position/Direction GLfloat light_position[] = { x, y, x, w }; W : Defines if the light source resides in infinity or in local scene. X, y, z: Location of light if light source resides in local view Or, Direction of light if the light source resides in infinity.
12
Next Class Review Discussion for Midterm Troubleshooting
13
Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.