C481 B581 Computer Graphics
Dana Vrajitoru
Material Properties in OpenGL
- 
glMaterialfv(side, type, array_of_values);
- 
glMaterialf(side, type, value);
- Side: GL_FRONT, GL_BACK, GL_FRONT_AND_BACK.
- 
Type: GL_SPECULAR, GL_AMBIENT, GL_DIFFUSE, GL_SHININESS.
- 
Once the material properties are defined, they replace the usual calls
to glColor3f(...);
Custom Lights
GLfloat light_ambient[]={1.0, 0.0, 0.0, 1.0};
GLfloat light_diffuse[]={1.0, 1.0, 0.0, 1.0};
GLfloat light_specular[]={1.0, 1.0, 1.0, 1.0};
 
Custom Material Properties
GLfloat mat_specular[]={1.0, 1.0, 1.0, 1.0};
GLfloat mat_diffuse[]={0.0, 0.0, 1.0, 1.0};
GLfloat mat_ambient[]={0.0, 0.5, 1.0, 1.0};
 
Redefining the Material Properties
- 
3 spheres with different material properties.
- 
In the display function, redefine the material properties before each of
them.
- 
Source code: my_sphere.cc.
 
Lights and glColor
- 
When the lighting is turned on, to be able to use the glColor, one must
enable some general material properties:
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
GL float spec={0.3, 0.3, 0.3, 0.1};
glMaterialfv(GL_FRONT, GL_SPECULAR, spec);
- 
After this, the material properties for each object can be redefined with
a simple glColor3f(...); call.
Examples:

 
Source code: teapot_amb_diff.cc 
(ambient and diffuse only) and
teapot_spec.cc (+specular, shininess of 50).
Last modified: April 12, 2005.
danav@cs.iusb.edu.