计算机图形学实验报告_第1页
计算机图形学实验报告_第2页
计算机图形学实验报告_第3页
计算机图形学实验报告_第4页
计算机图形学实验报告_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、华北电力大学科技学院实 验 报 告| 实验名称 OpenGL基本图元绘制实验 课程名称 计算机图形学 | 专业班级: 学生姓名: 学 号: 成 绩:指导教师:姜丽梅 实验日期: 二、所用仪器、设备 Windows系统,VisualC+,OpenGL及GLUT库三、实验方法与步骤先配置环境C:Program FilesMicrosoft Visual StudioVC98IncludeGLC:WINDOWSsystem32C:Program FilesMicrosoft Visual StudioVC98Lib然后通过VC+进行编译,源代码如:四:源代码实验一:#pragma comment(

2、linker, /subsystem:windows /entry:mainCRTStartup )#include #include #define DEG_TO_RAD 0.017453 static GLfloat theta = 0.0;GLfloat r = 1.0; /设置三角形的初始颜色 GLfloat g = 0.0; GLfloat b = 0.0;int singleb,doubleb;void display(void)glClear(GL_COLOR_BUFFER_BIT);/三角形换色glColor3f(r, g,b); r = r - 0.002; g = g +

3、0.002; b = b + 0.001; if(r 360.0)theta = theta - 360.0;glutPostRedisplay(); void spinDisplay1(void) glutPostRedisplay(); void myReshape(int w, int h)/指定平面上一个矩形裁剪区域,glViewport(0, 0, w, h);glMatrixMode(GL_PROJECTION);glLoadIdentity();if (w = h) gluOrtho2D(-1., 1., -1.*(GLfloat)h/(GLfloat)w, 1.*(GLfloa

4、t)h/(GLfloat)w);else gluOrtho2D(-1.*(GLfloat)w/(GLfloat)h, 1.*(GLfloat)w/(GLfloat)h, -1., 1.);void mouse(int button,int state,int x,int y) /鼠标定义 switch(button) case GLUT_LEFT_BUTTON: if(state = GLUT_DOWN ) glutIdleFunc(spinDisplay1); break; case GLUT_RIGHT_BUTTON: if(state = GLUT_DOWN) glutIdleFunc(

5、spinDisplay); break; default: break; void main(int argc, char* argv)glutInit(&argc,argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);glutInitWindowPosition(100, 100);glutInitWindowSize(500, 500);glutCreateWindow(spinning square);glClearColor(0.0, 0.0, 0.0, 1.0); glutDisplayFunc(display); glutReshape

6、Func(myReshape);glutIdleFunc(spinDisplay);glutMouseFunc(mouse); glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowPosition(600, 100);glutInitWindowSize(500, 500); doubleb=glutCreateWindow(spinning square); glClearColor(1.0, 1.0, 0.0, 0.1); glutDisplayFunc(display); glu

7、tReshapeFunc(myReshape); glutIdleFunc(spinDisplay); glutMouseFunc(mouse); glutMainLoop();实验二:#includestdafx.h#include#includeGLfloatvertices3=-1.0,-1.0,-1.0,1.0,-1.0,-1.0,1.0,1.0,-1.0,-1.0,1.0,-1.0,-1.0,-1.0,1.0,1.0,-1.0,1.0, 1.0,1.0,1.0,-1.0,1.0,1.0;staticGLfloattheta=0.0,0.0,0.0;staticGLintaxis=2;

8、staticGLdoubleviewer=0.0,0.0,5.0;voidpolygon(inta,intb,intc,intd)glBegin(GL_POLYGON);glVertex3fv(verticesa);glVertex3fv(verticesb);glVertex3fv(verticesc);glVertex3fv(verticesd);glEnd();voidcolorcube()/正前面glColor3f(1,1,1);polygon(4,5,6,7);/正背面glColor3f(1.0,0,0);polygon(0,3,2,1);glColor3f(0,1,0);polyg

9、on(2,3,7,6);glColor3f(0,0,1);polygon(0,4,7,3); glColor3f(1,1,0);polygon(1,2,6,5);glColor3f(0,1,1);polygon(0,1,5,4);voiddisplay()glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glClearDepth(1); glLoadIdentity(); /更新视点位置gluLookAt(viewer0,viewer1,viewer2,0.0,0.0,0.0,0.0,1.0,0.0);glRotatef(theta0,1.0,

10、0.0,0.0);glRotatef(theta1,0.0,1.0,0.0);glRotatef(theta2,0.0,0.0,1.0);colorcube(); glutSwapBuffers(); voidkeys(unsignedcharkey,intx,inty)/* 用 x, X, y, Y, z, and Z 键 移动视点 */ if(key=x)viewer0-=1.0;if(key=X)viewer0+=1.0;if(key=y)viewer1-=1.0;if(key=Y)viewer1+=1.0; if(key=z)viewer2-=1.0;if(key=Z)viewer2+

11、=1.0;display();voidmyReshape(intw,inth)glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION);glLoadIdentity();if(w360.0)thetaaxis-=360.0; display();int _tmain(int argc, _TCHAR* argv) /glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(300, 300); glutCreateW

12、indow(cube); glutDisplayFunc(display); glutReshapeFunc(myReshape); glutMouseFunc(mouse); glutKeyboardFunc(keys); glEnable(GL_DEPTH_TEST); glutMainLoop();return 0;五:实验结果与数据处理实验一:程序运行后,弹出两个窗口,里面的三角形旋转的同时逐渐变色;可用鼠标控制,点击左键三角形停止旋转,点击右键三角形继续旋转。实验二:运行程序,弹出一个黑色正方形,内有一个三维的正方体,当点击鼠标时正方体会转动,正方体的各个面的颜色均不相同。 按住键盘中z,x,y可以变大变小。 六:试验结论 通过一周的试验,感觉受益匪浅,学到了很多课堂上学不到的,我进一步加深了对

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论