光照

2016-06-17  本文已影响0人  zz张哲
//光照
float ambientLightColor[] = { 1.0f, 0.5f, 0.5f, 1.0f };
float diffuseLightColor[] = { 1.0f, 1.0f, 1.0f, 1.0f };
float specularLightColor[] = { 1.0f, 1.0f, 1.0f, 1.0f };
float lightPos[] = { 3.0f,5.0f,-5.0f,1.0f };
//float lightPos[] = { 0.2f,1.0f,1.0f,0.0f };  //方向光
glEnable(GL_LIGHT0);    //激活光源1
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLightColor);
glLightfv(GL_LIGHT0, GL_DIFFUSE, ambientLightColor);
glLightfv(GL_LIGHT0, GL_SPECULAR, ambientLightColor);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.5f);    //灯光衰减

float ambientM[] = { 0.1f,0.0f,0.0f,1.0f };
float diffuseM[] = { 0.1f,0.0f,0.0f,1.0f };
float specularM[] = { 1.0f,1.0f,1.0f,1.0f };
glMaterialfv(GL_FRONT, GL_AMBIENT, ambientM);    //材质
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseM);
glMaterialfv(GL_FRONT, GL_DIFFUSE, specularM);
glMaterialf(GL_FRONT, GL_SHININESS, 10.0f);

glEnable(GL_LIGHTING);   //光照的总开关
上一篇 下一篇

猜你喜欢

热点阅读