补充修改下列OpenGL代码 //这里图省事,直接把光照参数写在这边 Vector3f lightpos(0.0, 4, 2); Vector3f lightAmbient(0.6, 0.6, 0.6); Vector3f lightDiffuse(1.0, 1.0, 1.0); Vector3f lightSpecular(1.0, 1.0, 1.0); if (closest_hp.objIdx != -1) { int idx = closest_hp.objIdx; Mate
时间: 2024-04-06 08:29:10 浏览: 127
基于OpenGL的光照程序代码
5星 · 资源好评率100%
//在此处补充修改后的代码:
//光源参数
GLfloat lightpos[] = { 0.0f, 4.0f, 2.0f, 1.0f }; //光源位置
GLfloat lightAmbient[] = { 0.6f, 0.6f, 0.6f, 1.0f }; //环境光强度
GLfloat lightDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f }; //漫反射光强度
GLfloat lightSpecular[] = { 1.0f, 1.0f, 1.0f, 1.0f }; //高光光强度
if (closest_hp.objIdx != -1) {
int idx = closest_hp.objIdx;
Material mat = objects[idx].material;
//材质参数
GLfloat matAmbient[] = { mat.ambient.x, mat.ambient.y, mat.ambient.z, 1.0f };
GLfloat matDiffuse[] = { mat.diffuse.x, mat.diffuse.y, mat.diffuse.z, 1.0f };
GLfloat matSpecular[] = { mat.specular.x, mat.specular.y, mat.specular.z, 1.0f };
GLfloat matShininess[] = { mat.shininess };
//设置光源和材质参数
glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, matAmbient);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, matDiffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, matSpecular);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, matShininess);
}
阅读全文