Changing Material Properties
 

GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 }; 
GLfloat mat_ambient[] = { 0.7, 0.7, 0.7, 1.0 }; 
GLfloat mat_ambient_color[] = { 0.8, 0.8, 0.2, 1.0 }; GLfloat mat_diffuse[] = { 0.1, 0.5, 0.8, 1.0 }; 
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; 
GLfloat no_shininess[] = { 0.0 }; 
GLfloat low_shininess[] = { 5.0 }; 
GLfloat high_shininess[] = { 100.0 }; 
GLfloat mat_emission[] = {0.3, 0.2, 0.2, 0.0}; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
/* draw sphere in first row, first column * diffuse reflection only; no ambient or specular */ 
glPushMatrix(); 
glTranslatef (-3.75, 3.0, 0.0); 
glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat); 
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); 
glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat); 
glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess); glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); 
glutSolidSphere(1.0, 16, 16); 
glPopMatrix();

...

     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

Changing Material Properties (cont)

     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Changing Material Porperties with glColorMaterial()

void glColorMaterial(GLenum face, GLenum mode); 

    A change to the current color (using glColor*()) 
    immediately updates the specified material properties
    The face parameter can be GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK (the default). 
    The mode parameter can be GL_AMBIENT, GL_DIFFUSE, GL_AMBIENT_AND_DIFFUSE (the default), GL_SPECULAR, or GL_EMISSION. 
    At any given time, only one mode is active. 
    No effect on color-index lighting.

    glEnable(GL_COLOR_MATERIAL); 
    glColorMaterial(GL_FRONT, GL_DIFFUSE);
    /* now glColor* changes diffuse reflection */ 
    glColor3f(0.2, 0.5, 0.8); 
    /* draw some objects here */ 
     

    glColorMaterial(GL_FRONT, GL_SPECULAR);
    /* glColor* no longer changes diffuse reflection */
    /* now glColor* changes specular reflection */ 
    glColor3f(0.9, 0.0, 0.2); 
    /* draw other objects here */ 
    glDisable(GL_COLOR_MATERIAL);
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  The lighting calculation (summary)

     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Homework
  • Download the lightposition tar file and run the programs "lightposition" and "lightmaterial".  Manipulate the values to change lighting and material definitions.

  •  

  • Extra Credit: Go back to the VRML documentation and create a scene with objects which have material definitions and lights.

  •  

     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  End of Presentation
  • Fin 6

  •  

     
     
     

  •  

  •  

     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  End of Presentation
  • Fin 7

  •  

     
     
     

  •  

  •  

     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  End of Presentation
  • Fin 8

  •  

     
     
     

  •  

  •  

     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  End of Presentation
  • Fin 9

  •  

     
     
     

  •  

  •  

     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  End of Presentation
  • Fin 10

  •  

     
     
     

  •  

  •