1 computer graphics TA Nouf AlHarbi Nouf Naief
1 computer graphics TA: Nouf Al-Harbi Nouf. Naief. net nouf 200@hotmail. com
Computer graphics lab 10 Lighting in Open. GL
3 Without Lighting With Lighting
4 4 steps to put light into your scene 1 2 Enable Lighting • Enable light • sources 4 3 Define material • properties for objects Set properties for • light sources
5 Put light into Open. GL 1/4 How 1. to apply lighting in Open. GL Use gl. Enable( GL_LIGHTING) to enable lighting.
6 Put light into Open. GL 2/4 How 2. to apply lighting in Open. GL Enable light sources. Up to 8 lights are available (GL_LIGHT 0 ~ GL_LIGHT 7). Enable a light by calling to gl. Enable( GL_LIGHTi).
7 Put light into Open. GL 3/4 3. Set light source properties by calling to gl. Lightfv(… ) gl. Light{if}[v](light, pname, value ); light can be GL_LIGHT 0~ GL_LIGHT 7 pname is the properties of the light value is the value of pname.
8 Light properties 1/2 [1] Position ( x, y, z, w ) W is ZERO, Directional light (x, y, z) W specify its direction. is NONZERO, Positional light (x, y, z) specify the location of the light source.
9 Light properties 1/2
10 Light properties 2/2 [2] Light Types 1. Ambient light Light that has been scattered by the environment. 2. Diffuse light Light 3. that come from one direction. Specular light Light that come from particular direction that tend to bounce off the surface in a preferred direction.
11 Put light into Open. GL 3/4
12 Put light into Open. GL 4/4 When you enable lighting , the gl. Colorcall no longer has any effect. we move to a different model for coloring an object 1. Diffuse 2. Ambient 3. Specular& Shininess control the size and brightness of the highlight. (values range 0~128) Emission Since most real-world objects (except lights) don't emit light, you'll probably use this feature mostly to simulate lamps and other light sources in a scene.
13 Put light into Open. GL 4/4 Define material properties for objects in the scene by calling to gl. Materialfv( … ). void gl. Material{if}[v](face, pname, value); face can be GL_FRONT GL_BACK GL_FRONT_AND_BACK
14 Put light into Open. GL 4/4 Define material properties for objects in the scene by calling to gl. Materialfv( … ). void gl. Material{if}[v](face, pname, value); param. Name selects which material property to change v GL_AMBIENT sets the ambient color v GL_DIFFUSE sets diffuse color v GL_SPECULAR sets the specular color v GL_SHININESS sets the specular exponent v GL_EMISSION sets the emissive
15 Put light into Open. GL 4/4 Define material properties for objects in the scene by calling to gl. Materialfv( … ). void gl. Material{if}[v](face, pname, value); Value is the value to set
16 Put light into Open. GL 4/4 Diffuse
17 Put light into Open. GL 4/4 Ambient
18 Put light into Open. GL 4/4 Ambient + Diffuse
19 Put light into Open. GL 4/4 Specular +Shininess
20 Put light into Open. GL 4/4 Emission
21
22 REFERENCES: Materials of this lab are prepared using: v Computer Graphics Lab -1 st semester – 20102011 by : Ins. Ruwaida Al-harbi v An Introduction to Graphics Programming with Open. GL by : Toby Howard, School of Computer Science, University of Manchester
- Slides: 22