Rendering  Illuminated Objects
  • To render lit surfaces OpenGL must:
    • Define normal vectors for each vertex of all the objects 
    • Create, select, and position one or more light sources. 
    • Create and select a lighting model
    • Define material properties for the objects


     (walk through code)
     
     

  • Programming Notes:
    • Make sure each light is enabled after defining
    • Make sure lighting is enabled
    • Changes in lighting may be utilized with display lists for potential performance inprovements.

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Creating light souces
  • Fin 2

  •  
void glLight{if}(GLenum light, GLenum pname, TYPE param); 
void glLight{if}v(GLenum light, GLenum pname, TYPE *param); 
    Creates the light specified by light, which can be GL_LIGHT0, GL_LIGHT1, ... , or GL_LIGHT7.
     
     
  •  

  •  

     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Lighting Parameters
     

    NOTE!  Default values of GL_DIFFUSE and GL_SPECULAR apply only to GL_LIGHT0
    (0.0, 0.0, 0.0, 1.0) for the other lights
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Specifying the position and color of a light 
     
    GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; 
    GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; 
    GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; 
    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); 
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); 
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); 
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);

    Note: Remember to turn on each light with glEnable(). (See "Enabling Lighting" for more information about how to do this.)
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Color
  • GL_DIFFUSE color correlates to the "typical" color of a light\
    • Defines the color and intensity that a light adds to the scene
  •  GL_SPECULAR color defines what color specular highlights will be

  • (picture of angular reflectivity)
     
     
     
     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 


 
 
  Position and Attenuation
  • Lights can be considered directional or positional
    • Rays of directional lights can be considered to be parallel
    • The sun is an example of a real-world directional light 
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; 
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

The light position is defined as (x, y, z, w)

w  = 0.0:    (x, y, z) = light direction
w  != 0.0:   (x, y, z) = light position
     
     
  •  By Default GL_POSITION = {0, 0, 1, 0} (directional, along the -Z axis)
  • Positional lights radiate in all directions by default
    • may be defined as spotlights
     
     
     
     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Programming Note:
  • Large Polygons with local (positional) lights will interpolate the light values across the polygon
    • A problem for LARGE polygons (they may appear darker)
    • Break the polygon into smaller polygonal pieces

     
     
     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  End of Presentation
  • Fin 8

  •  

     
     
     

  •  

  •  

     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  End of Presentation
  • Fin 9

  •  

     
     
     

  •  

  •  

     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  End of Presentation
  • Fin 10

  •  

     
     
     

  •  

  •