资源描述:
《计算机图形学光照模型》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、计算机图形学光照模型姓名:郭弘凌指导教师:杜宏明学号:13021228班级:机械5班光照模型一、算法要求理解OpenGL光照函数二、软件选择操作平台:为了配置OpenGL,选择的编程平台为VC6.0。三、具体代码及相关说明#include#includeusingnamespacestd;voiddisplay(){glClear(GL_COLOR_BUFFER_BIT
2、GL_DEPTH_BUFFER_BIT);glMatrixMode(GL_MODELVIEW);glLoadIdentity()
3、;gluLookAt(0.6,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0);glScalef(1,2,1);glutSolidCube(1);//glutWireCube(1);线框glutSwapBuffers();glFlush();}voidreshape(intw,inth){glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(-5.0,5.0,-5.0,5.0,-5.0,5.0);}voidinit(){GLfloa
4、tlight_position[]={1.0,1.0,2.0,0.0};GLfloatlight_ambient[]={0.0,0.0,0.0,1.0};GLfloatlight_diffuse[]={1.0,1.0,1.0,1.0};GLfloatlight_specular[]={1.0,1.0,1.0,1.0};//光照值和坐标glLightfv(GL_LIGHT0,GL_POSITION,light_position);glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient);glLightfv(
5、GL_LIGHT0,GL_DIFFUSE,light_diffuse);glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular);//设置和启用光照0glEnable(GL_LIGHTING);//启用光照glEnable(GL_LIGHT0);//激活第一个光源glDepthFunc(GL_LESS);glEnable(GL_DEPTH_TEST);//隐藏表面删除glClearColor(0.0,0.0,0.0,1.0);glColor3f(0.0,0.0,0.0);}intmain(intarg
6、c,char**argv){glutInit(&argc,argv);glutInitDisplayMode(GLUT_DOUBLE
7、GLUT_RGB);glutInitWindowSize(500,500);glutInitWindowPosition(0,0);glutCreateWindow("cube");glutReshapeFunc(reshape);glutDisplayFunc(display);init();glutMainLoop();}一、运行结果