资源描述:
《实验七 光照和材质.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验八光照和材质一、实验目的1、进一步掌握3D编程概念:2、了解和掌握三维场景中如何设置光照和材质效果二、实验内容1.上机运行以下程序,并修改光照和材质的参数,观察对场景生成的影响。#includevoiddisplay(void);voidreshape(int,int);voidlighting(void);intmain(intargc,char**argv){glutInit(&argc,argv);glutInitWindowSize(400,400);glutInit
2、WindowPosition(0,0);glutInitDisplayMode(GLUT_SINGLE
3、GLUT_RGBA
4、GLUT_DEPTH);glutCreateWindow("Planet");glutDisplayFunc(display);glutReshapeFunc(reshape);glutMainLoop();}voidlighting(void){GLfloatmat_diffuse[]={1.0,0.0,0.0,1.0};GLfloatmat_specular[]={0.
5、0,0.0,1.0,1.0};GLfloatmat_ambient[]={0.0,1.0,0.0,1.0};GLfloatmat_shininess[]={50.0};GLfloatlight_specular[]={1.0,1.0,1.0,1.0};GLfloatlight_diffuse[]={1.0,1.0,1.0,1.0};GLfloatlight_ambient[]={0.0,0.0,0.0,1.0};GLfloatlight_position[]={5.0,5.0,10.0,0.0}
6、;glClearColor(0.0,0.0,0.0,0.0);glShadeModel(GL_SMOOTH);//zbufferenableglEnable(GL_DEPTH_TEST);//enablelightingglEnable(GL_LIGHTING);//setlightpropertyglEnable(GL_LIGHT0);glLightfv(GL_LIGHT0,GL_POSITION,light_position);glLightfv(GL_LIGHT0,GL_DIFFUSE,l
7、ight_diffuse);glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular);glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient);//setmaterialpropertyglMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);glMaterialfv(GL_FRONT,GL_AM
8、BIENT,mat_ambient);glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);}voiddisplay(void){lighting();glClear(GL_COLOR_BUFFER_BIT
9、GL_DEPTH_BUFFER_BIT);glutSolidSphere(0.8,128,128);glFlush();}voidreshape(intw,inth){glViewport(0,0,(GLsizei)w,(GLsizei)h);g
10、lMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();}2.3D旋转世界的光照和材质设置(选作)附属程序rotatingtorus-withlight&material.cpp为一视点保持不变的3D旋转程序,3D场景为一个圆环、一个小球和一个以四边形为基本单位的方块墙包围盒,且小球和圆环在“方块墙”的包围
11、盒中。视点设在正前方观察物体,小球绕着环心某处不停旋转,并和圆环一起绕着环心不停旋转。并且场景实现了光照和材质效果,将程序仔细研读,运行查看光照效果,了解OpenGL光照材质程序代码编写。图1带光照和材质效果的3D场景1.回答下列问题,程序用到几个光源?光源的性质?光源的位置相对于物体位置如何?2.改变光源参数,如光源的位置、光的三个分量强度、光源的数量等参数,光照效果受到什么影响?3.改变材质参数,材质分量、材质系数等,光照效果又会受到什么影响?4.将3D圆环物体替换为一个立方体,一个茶壶或其