资源描述:
《实验7OpenGL光照》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、........实验7OpenGL光照一、实验目的了解掌握OpenGL程序的光照与材质,能正确使用光源与材质函数设置所需的绘制效果。二、实验内容(1)下载并运行NateRobin教学程序包中的lightmaterial程序,试验不同的光照与材质系数;(2)运行示范代码1,了解光照与材质函数使用。三、实验原理为在场景中增加光照,需要执行以下步骤:(1)设置一个或多个光源,设定它的有关属性;(2)选择一种光照模型;(3)设置物体的材料属性。具体见教材第8章8.6节用OpenGL生成真实感图形的相关内容。四、实验代码.专业学习资料.......
2、..#include#includestaticintyear=0,day=0;voidinit(void){GLfloatmat_specular[]={1.0,1.0,1.0,1.0};GLfloatmat_shininess[]={50.0};GLfloatlight_position[]={1.0,1.0,1.0,0.0};GLfloatwhite_light[]={1.0,1.0,1.0,1.0};GLfloatLight_Model_Ambient[]={0.2,0.2,0.2,1.0
3、};glClearColor(0.0,0.0,0.0,0.0);glShadeModel(GL_SMOOTH);//glMaterialfv(材质指定,单值材质参数,具体指针);glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);//镜面反射光的反射系数.专业学习资料.........glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);//镜面反射指数//glLightfv(光源,属性名,属性值);glLightfv(GL_LIGHT0,GL_PO
4、SITION,light_position);//光源位置glLightfv(GL_LIGHT0,GL_DIFFUSE,white_light);//漫放射光分量强度glLightfv(GL_LIGHT0,GL_SPECULAR,white_light);//折射光强度glLightModelfv(GL_LIGHT_MODEL_AMBIENT,Light_Model_Ambient);//光源2GL_LIGHT1GLfloatmat_specular1[]={1.0,1.0,1.0,1.0};GLfloatmat_shininess1[]
5、={50.0};GLfloatlight_position1[]={0.0,0.0,0.0,0.0};GLfloatred_light[]={1.0,0.0,0.0,1.0};GLfloatLight_Model_Ambient1[]={0.2,0.2,0.2,1.0};.专业学习资料.........glLightfv(GL_LIGHT1,GL_POSITION,light_position1);//光源位置glLightfv(GL_LIGHT1,GL_DIFFUSE,red_light);//漫放射光分量强度glLightfv(GL_
6、LIGHT1,GL_SPECULAR,red_light);//折射光强度glLightModelfv(GL_LIGHT_MODEL_AMBIENT,Light_Model_Ambient1);//开启灯光glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);glEnable(GL_LIGHT1);glEnable(GL_DEPTH_TEST);}voiddisplay(void){glClear(GL_COLOR_BUFFER_BIT
7、GL_DEPTH_BUFFER_BIT);.专业学习资料........
8、.glPushMatrix();//定义太阳的材质并绘制太阳{GLfloatsun_mat_ambient[]={1.0f,0.0f,0.0f,1.0f};//定义材质的环境光颜色,偏红色GLfloatsun_mat_diffuse[]={0.5f,0.5f,0.0f,1.0f};//定义材质的漫反射光颜色,偏红色GLfloatsun_mat_specular[]={1.0f,0.0f,0.0f,1.0f};//定义材质的镜面反射光颜色,红色GLfloatsun_mat_emission[]={0.0f,0.0f,0.0f,1.0f};/
9、/定义材质的辐射光颜色,为0GLfloatsun_mat_shininess=32.0f;glMaterialfv(GL_FRONT,GL_AMBIENT,sun_mat_ambient);g