在OpenGL中设置金属材料(如银),可以通过以下步骤实现:
GLfloat silver_ambient[] = {0.19225, 0.19225, 0.19225};
GLfloat silver_diffuse[] = {0.50754, 0.50754, 0.50754};
GLfloat silver_specular[] = {0.508273, 0.508273, 0.508273};
GLfloat silver_shininess = 0.4;
glMaterialfv(GL_FRONT, GL_AMBIENT, silver_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, silver_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, silver_specular);
glMaterialf(GL_FRONT, GL_SHININESS, silver_shininess);
GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0};
GLfloat light_ambient[] = {0.2, 0.2, 0.2, 1.0};
GLfloat light_diffuse[] = {0.8, 0.8, 0.8, 1.0};
GLfloat light_specular[] = {0.8, 0.8, 0.8, 1.0};
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glBegin(GL_TRIANGLES);
// 绘制金属三角形
glEnd();
通过以上步骤,就可以在OpenGL中设置金属材料(如银)了。
领取专属 10元无门槛券
手把手带您无忧上云