光照材质
/*
* material.c
* This program demonstrates the use of the GL lighting model.
* Several objects are drawn using different material characteristics.
* A single light source illuminates the objects.
*/
#include <glut.h>
/* Initialize z-buffer, projection matrix, light source,
* and lighting model. Do not specify a material property here.
*/
void init(void)
{
//分别设定光源的环境光、漫反射光、镜面反射光和光源的位置
GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat position[] = { 0.0, 3.0, 2.0, 0.0 };
GLfloat lmodel_ambient[] = { 0.4, 0.4, 0.4, 1.0 }; //全局环境光
GLfloat local_view[] = { 0.0 };
glClearColor(0.0, 0.1, 0.1, 0.0);
glEnable(GL_DEPTH_TEST); //启用深度检测
glShadeModel(GL_SMOOTH);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0); //打一盏光
}
/* Draw twelve spheres in 3 rows with 4 columns.
* The spheres in the first row have materials with no ambient reflection.
* The second row has materials with significant ambient reflection.
* The third row has materials with colored ambient reflection.
======================================
第一行小球的材质没有环境光的影响
第二行小球的材质有环境光的影响
第三行小球的材质受着有颜色的环境观影响
======================================
*
* The first column has materials with blue, diffuse reflection only.
* The second column has blue diffuse reflection, as well as specular
* reflection with a low shininess exponent.
* The third column has blue diffuse reflection, as well as specular
* reflection with a high shininess exponent (a more concentrated highlight).
* The fourth column has materials which also include an emissive component.
=======================================================
第一列小球的材质是蓝色的,并且仅受漫反射的影响
第二列小球的材质较第一列多了一个低镜面反射指数的影响
第三列小球的材质较第一列多了一个高镜面反射指数的影响
第四列小球的材质较第一列多了一个材质的辐射光指数的影响