资源描述:
《计算机图形学-opengl基本光照》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、计算机图形学与可视化(含OpenGL)实验报告实验名称:OpenGL基本光照(实验五)班级:信09-1学号:2108190911211姓名:王杰【实验目的】1.掌握GLUT实用包中创建多面体以及二次曲面的函数2.掌握OpenGL中的基本光照函数【实验内容】1、源程序#includevoidinit(void){glClearColor(1.0,1.0,1.0,0.0);glShadeModel(GL_SMOOTH);glEnable(GL_LIGHTING);glEnable(GL_LIGHT0
2、);GLfloatlight_position[]={1.0,1.0,1.0,0.0};//光源位置坐标GLfloatlight_ambient[]={0.8,0.5,0.0,1.0};//环境光GLfloatlight_diffuse[]={0.0,0.8,1.0,1.0};//漫反射光GLfloatlight_specular[]={0.0,1.0,1.0,1.0};//镜面光glLightfv(GL_LIGHT0,GL_POSITION,light_position);glLightfv(GL_LIGHT
3、0,GL_AMBIENT,light_ambient);glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular);GLfloatmaterial_ambient[]={0.8,0.5,0.0,1.0};//环境光GLfloatmaterial_diffuse[]={0.0,0.8,1.0,1.0};//漫反射光GLfloatmaterial_specular[]={0.0,1.0,1
4、.0,1.0};//镜面光glMaterialfv(GL_FRONT,GL_AMBIENT,material_ambient);//材质环境光glMaterialfv(GL_FRONT,GL_DIFFUSE,material_diffuse);//材质漫反射光glMaterialfv(GL_FRONT,GL_SPECULAR,material_specular);//材质镜面光}voiddisplay(void){glClear(GL_COLOR_BUFFER_BIT);glColor3f(0.1,0.1,0.
5、1);glTranslatef(-0.5,0.0,-3.0);glRotatef(10,3,3,3);glutWireOctahedron();//八面体北京建筑工程学院理学院信息与计算科学计算机图形学与可视化(含OpenGL)实验报告glFlush();glTranslatef(1.7,0.0,-3.0);glutWireTorus(0.3,0.2,10,10);//环面glFlush();}voidreshape(intw,inth){glViewport(0,0,(GLsizei)w,(GLsizei)h
6、);glMatrixMode(GL_PROJECTION);glLoadIdentity();if(w<=h)glOrtho(-1.5,1.5,-1.5*(GLfloat)h/(GLfloat)w,1.5*(GLfloat)h/(GLfloat)w,-10.0,10.0);elseglOrtho(-1.5*(GLfloat)w/(GLfloat)h,1.5*(GLfloat)w/(GLfloat)h,-1.5,1.5,-10.0,10.0);glMatrixMode(GL_MODELVIEW);glLoadId
7、entity();}intmain(intargc,char**argv){glutInit(&argc,argv);glutInitDisplayMode(GLUT_SINGLE
8、GLUT_RGBA
9、GLUT_DEPTH);glutInitWindowSize(500,500);glutInitWindowPosition(100,100);glutCreateWindow(argv[0]);init();glutDisplayFunc(display);glutReshapeFunc(reshape);gl
10、utMainLoop();return0;1、运行结果截图北京建筑工程学院理学院信息与计算科学计算机图形学与可视化(含OpenGL)实验报告1、多面体、二次曲面函数功能及使用说明glShadeModel(GL_SMOOTH);glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);GLfloatlight_position[]={1.0,1.0,1.0,0.