实验 2 设计一个真实感图形显示系统
选题 60 分:有灯光、材质、纹理 (p203,p206) 的场景 80 分:+交互控制场景( figure11.1.c ) 100 分:+读入多边形物体+ Bezier 曲面
#include #define myAngle 45. float theta = 22.; GLfloat red[]={1.0, 0.0, 0.0, 1.0}; void myinit(void) { GLfloat light_position0[]={ 0.0, 10.0, 0.0, 1.0 }; GLfloat light_color[]={ 1.0, 1.0, 1.0, 1.0 }; GLfloat ambient_color[]={ 0.3, 0.3, 0.3, 1.0 }; glClearColor( 0.7, 0.7, 0.7, 1.0 ); glLightfv(GL_LIGHT0, GL_POSITION, light_position0 ); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color ); glLightfv(GL_LIGHT0, GL_SPECULAR, light_color ); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_color ); glClearDepth(1.0f); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST ); glEnable(GL_LIGHTING); // so lighting models are used glEnable(GL_LIGHT0); // we'll use LIGHT0 } void display( void ) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0,0,5,0,0,-1,0,1,0); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red ); glRotatef(theta,0,1,0); glScalef(1.0f, 2.0f, 1.0f); glutSolidTeapot(1.0); glutSwapBuffers(); } void reshape(int w,int h) { glViewport(0,0,(GLsizei)w,(GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(myAngle,(float)w/(float)h,0.02,100.0); glutPostRedisplay(); } void animate(void) { theta += 0.05; glutPostRedisplay(); } int main(int argc, char** argv) { glutInit(&argc,argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(800, 800); glutInitWindowPosition(0, 0); glutCreateWindow(" 实验 "); glutDisplayFunc(display); glutReshapeFunc(reshape); glutIdleFunc(animate); myinit(); glutMainLoop(); }
收集实验报告时间 6 月 25 日教师机收集 每位同学需上交 学号 + 姓名 命名的实验报 告(包括附录的源程序清单)实验报 告