资源描述:
《OpenGL中真实感图形的显示实现》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验名称OpenGL中真实感图形的显示实现一、实验目的学习基于OpenGL真实感图形显示的原理与实现方法。二、实验内容利用向导生成应用程序框架,参考示例编写实现三维图形的应用程序,增加光照与材质效果实现真实感图形的显示。三、实验步骤1.利用向导生成应用程序框架。2.添加相应的函数,绘制立方体(参照上课给的实例)。3.添加相应的函数,实现三维球体的绘制。4.增加光源,并设置光源参数与材质参数,观察显示效果。实验代码及程序运行结果截图如下://2008cube.cpp:Definestheentrypointforthecon
2、soleapplication.//#include"stdafx.h"#include"gl/glut.h"#include"math.h"voidmyinit(){glClearColor(1.0,1.0,1.0,0.0);glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(-1.5,1.5,-1.5,1.5,-1.5,1.5);}voiddraw_cube(){glClear(GL_COLOR_BUFFER_BIT);glColor3f(1.0,0.0,0.0);
3、glBegin(GL_POLYGON);glVertex3f(0.0,0.0,0.0);glVertex3f(0.0,1.0,0.0);glVertex3f(1.0,1.0,0.0);glVertex3f(1.0,0.0,0.0);glEnd();glColor3f(0.0,1.0,0.0);glBegin(GL_POLYGON);glVertex3f(0.0,0.0,0.0);glVertex3f(0.0,1.0,0.0);glVertex3f(0.0,1.0,1.0);glVertex3f(0.0,0.0,1.0);g
4、lEnd();glColor3f(0.0,0.0,1.0);glBegin(GL_POLYGON);glVertex3f(0.0,0.0,1.0);glVertex3f(0.0,1.0,1.0);glVertex3f(1.0,1.0,1.0);glVertex3f(1.0,0.0,1.0);glEnd();glColor3f(1.0,1.0,0.0);glBegin(GL_POLYGON);glVertex3f(1.0,0.0,0.0);glVertex3f(1.0,1.0,0.0);glVertex3f(1.0,1.0,
5、1.0);glVertex3f(1.0,0.0,1.0);glEnd();glColor3f(1.0,0.0,1.0);glBegin(GL_POLYGON);glVertex3f(0.0,1.0,0.0);glVertex3f(1.0,1.0,0.0);glVertex3f(1.0,1.0,1.0);glVertex3f(0.0,1.0,1.0);glEnd();}voiddisplay(){glClear(GL_COLOR_BUFFER_BIT);glColor3f(1.0,0.0,0.0);gluLookAt(0.5
6、,0.5,0.0,1.0,1.0,1.0,1.0,0.0,1.0);glutWireCube(0.5);draw_cube();glFlush();}voidmain(intargc,char*argv[]){glutInit(&argc,argv);glutInitDisplayMode(GLUT_SINGLE
7、GLUT_RGB);glutInitWindowSize(300,300);glutCreateWindow("立方体的绘制");glutDisplayFunc(display);myinit();glutMai
8、nLoop();}//2008sphere.cpp:Definestheentrypointfortheconsoleapplication.//#include"stdafx.h"#include"gl/glut.h"#include"math.h"#defineM_PI3.1415926voiddraw_sphere(){doublec=M_PI/180.0;floatphi,phir,theta,thetar,x,y,z,phir20;glColor3f(1.0,1.0,1.0);for(phi=-10.0;phi<
9、100.0;phi+=4.0){phir=c*phi;phir20=c*(phi+20);glBegin(GL_QUAD_STRIP);for(theta=-200.0;theta<=200.0;theta+=1.0){thetar=c*theta;x=sin(thetar)*cos(phir);y=c