我试图让一个有8种不同光源的模型工作。我想这样做,以便表面到达其最大值"接近一个光源时的值,但是如果多个光线靠近表面,代码的工作方式现在就会增加它的亮度,直到它几乎是纯白色。
对于表面,我使用:
float white[] = {1,1,1,1};
float black[] = {0,0,0,1};
float medium[] = {.5,.5,.5,.5};
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,white);
glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,black);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,medium);
对于八盏灯:
int glLightConstant = GL_LIGHT0 + i;
float Diffuse[] = {(float)0.01*50 ,(float)0.01*50 ,(float)0.01*50 ,1.0f};
float Specular[] = {(float)0.01*0,(float)0.01*0,(float)0.01*0,1.0f};
float Position[] = {(float)positions[i].x,(float)positions[i].y,(float)positions[i].z,(float)1.0};
glEnable(GL_NORMALIZE);
glEnable(GL_LIGHTING);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,0.0);
glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
glEnable(glLightConstant);
if(i == 0) {
float Ambient[] = {(float)0.01*0 ,(float)0.01*0 ,(float)0.01*0 ,1.0f};
glLightfv(glLightConstant,GL_AMBIENT ,Ambient);
}
glLightfv(glLightConstant,GL_DIFFUSE ,Diffuse);
glLightfv(glLightConstant,GL_SPECULAR,Specular);
glLightfv(glLightConstant,GL_POSITION,Position);
我意识到环境光是0,我可能会在以后改变它。