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

下载本文档

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

文档简介

1、精选优质文档-倾情为你奉上实验一1. (1)三角形:#include <glut.h> / glut.h includes gl.h and glu.hvoid init(void) glClearColor(0.0, 0.0, 0.0, 0.0);void reshape(int w, int h) glViewport(0, 0, (GLsizei)w, (GLsizei)h);glMatrixMode(GL_PROJECTION);/ 指定哪一个矩阵是当前矩阵glLoadIdentity();/重置当前指定的矩阵为单位矩阵。gluOrtho2D(-1.0, 1.0, -1.0

2、, 1.0); / The para are: (left, right, bottom, top) 定义二维正交投影矩阵glMatrixMode(GL_MODELVIEW); /指定哪一个矩阵是当前矩阵void display(void) glClear(GL_COLOR_BUFFER_BIT); / Clear the frame bufferglColor3f(0.0, 1.0, 0.0); / Set current color to greenglBegin(GL_POLYGON); / Draw the triangleglVertex2f(-0.7, -0.7);glVertex

3、2f(0.7, -0.7);glVertex2f(0, 0.7);glEnd();glFlush(); / Force to display the new drawings immediatelyint main(int argc, char *argv) glutInit(&argc, argv); / Initialize GLUT function callingsglutInitWindowSize(400, 400);glutInitWindowPosition(200, 100); / in numbers of pixelsglutCreateWindow("

4、Green Triangle");glutDisplayFunc(display); / is created or re-drewinit(); / Invoke this function for initializationglutMainLoop(); / Enter the event processing loopreturn 0; / Indicate normal termination/ (Required by ANSI C)/ 操作,定义事件回调函数(2)点:void display()glClear(GL_COLOR_BUFFER_BIT); / Clear

5、the frame bufferglColor3f(0.0, 1.0, 0.0); / Set current color to greenglPointSize(10.);glBegin(GL_POINTS);glVertex2i(0.5,0.5);glEnd();glFlush(); / Force to display the new drawings immediately(3)线段:void display()glClear(GL_COLOR_BUFFER_BIT); / Clear the frame bufferglColor3f(0.0, 1.0, 0.0); / Set cu

6、rrent color to greenglLineWidth(3.0);glBegin(GL_LINES);glVertex3f(0., 0., 0.);glVertex3f(0., 1., 0.);glEnd();glFlush(); / Force to display the new drawings immediately(4)四边形:void display()glClear(GL_COLOR_BUFFER_BIT); / Clear the frame bufferglColor3f(1.0, 0.0, 0.0); / Set current color to greenglRe

7、ctf(0.6, 0.3, 0.2, 0.8);int vertex1 = 0.6, 0.3;int vertex2 = 0.2, 0.8;glRectiv(vertex1, vertex2);glFlush(); / Force to display the new drawings immediately2. 立方体:3. void reshape(int w, int h)4. 5. glViewport(0, 0, w, h);6. glMatrixMode(GL_PROJECTION);7. glLoadIdentity();8. glOrtho(-3.0, 3.0, -3.0, 3

8、.0, -3.0, 3.0);9. 10. void display()11. glClear(GL_COLOR_BUFFER_BIT); / Clear the frame buffer12. glMatrixMode(GL_MODELVIEW);13. glLoadIdentity();14. gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);15. glutWireCube(0.5);16. glutSwapBuffers();17. glColor3f(0.0, 1.0, 0.0);18. glBegin(GL_LINE_LO

9、OP); /Green19. glVertex3f(0., 0., 0.); glVertex3f(0., 2, 0.);20. glVertex3f(2, 2, 0.); glVertex3f(2, 0., 0.);21. glEnd();22. glColor3f(1.0, 1.0, 0.0);23. glBegin(GL_LINE_LOOP); /Yellow24. glVertex3f(0., 0., 2); glVertex3f(2, 0., 2);25. glVertex3f(2, 2, 2); glVertex3f(0., 2, 2);26. glEnd();27. glColo

10、r3f(0.0, 1.0, 1.0);28. glBegin(GL_LINES); /Cyan29. glVertex3f(0., 0., 0.); glVertex3f(0., 0., 2);30. glVertex3f(0., 2, 0.); glVertex3f(0., 2, 2);31. glVertex3f(2, 0., 0.); glVertex3f(2, 0., 2);32. glVertex3f(2, 2, 0.); glVertex3f(2, 2, 2);33. glEnd();34. glFlush(); / Force to display the new drawing

11、s immediately3.(1)三角形条带void display()glClear(GL_COLOR_BUFFER_BIT); / Clear the frame bufferGLfloat v0 = 0., 0.3 ,v1 = 0.2, 0.6 ,v2 = 0.4, 0.3 ,v3 = 0.5, 0.6 ,v4 = 0.6, 0.3 ,v5 = 0.8, 0.6 ,glColor3f(1.0);glBegin(GL_TRIANGLE_STRIP);/三角形条带函数glVertex2fv(v0); glVertex2fv(v1);glVertex2fv(v2);glVertex2fv(v

12、3);glVertex2fv(v4);glVertex2fv(v5); glEnd();glFlush(); / Force to display the new drawings immediately3.(2)三角形扇形GLfloat v0 = 0., 0.3 ,v1 = 0.3, 0.7 ,v2 = 0.5, 0.65 ,v3 = 0.5, 0.5,v4 = 0.45, 0.4 ,v5 = 0.3, 0.35 ,glColor3f(1.0);glBegin(GL_TRIANGLE_FAN);/共享一个顶点glVertex2fv(v0);glVertex2fv(v1);glVertex2f

13、v(v2);glVertex2fv(v3);glVertex2fv(v4);glVertex2fv(v5); glEnd();glFlush(); / Force to display the new drawings immediately实验二1.点glColor3f(0.0, 1.0, 0.0);glPointSize(3.);glBegin(GL_POINTS);glVertex3f(0.1, 0.5, 0);glColor3f(1.0, 1.0, 0.0);glPointSize(5.);glBegin(GL_POINTS);glVertex3f(0.5, 0.5, 0);glCol

14、or3f(1.0, 0.0, 0.0);glPointSize(10.);glBegin(GL_POINTS);glVertex3f(0.3, 0.4, 0);glColor3f(0.0, 0.0, 1.0);glPointSize(1.);glBegin(GL_POINTS);glVertex3f(0.2, 0.6, 0);glColor3f(1.0, 1.0, 1.0);glPointSize(4.);glBegin(GL_POINTS);glVertex3f(0.3, 0.5, 0);glEnd();glFlush(); / Force to display the new drawin

15、gs immediately2.直线glColor3f(0.0, 1.0, 0.0);glLineWidth(1.0);glBegin(GL_LINES);glVertex3f(0.3, 0.1, 0.0);glVertex3f(0.3, 0.5, 0.0);/垂直距离glColor3f(1.0, 1.0, 0.0);glLineWidth(3.);/宽度glBegin(GL_LINES);glVertex3f(0.2, 0.1, 0.0);glVertex3f(0.2, 0.5, 0.0);glColor3f(1.0, 0.0, 0.0);glLineWidth(5.);glBegin(GL

16、_LINES);glVertex3f(0.5, 0.1, 0.0);glVertex3f(0.5, 0.5, 0.0);glEnd();glFlush(); / Force to display the new drawings immediately3.直线,虚线,点划线glColor3f(1.0, 0.0, 0.0);glLineWidth(2.0);glBegin(GL_LINES);glVertex2f(0.0, 0.3);glVertex2f(0.8, 0.3);glEnd();glColor3f(1.0, 0.0, 0.0);glEnable(GL_LINE_STIPPLE);gl

17、LineStipple(1, 0x0101);glLineWidth(2.0);glBegin(GL_LINES);glVertex2f(0.0, 0.5);glVertex2f(0.8, 0.5);glEnd(); glColor3f(1.0, 0.0, 0.0); glEnable(GL_LINE_STIPPLE);glLineStipple(1, 0xffcc); glLineWidth(2.0); glBegin(GL_LINES); glVertex2f(0.0, 0.8); glVertex2f(0.8, 0.8);glEnd();4.顶点不同颜色的三角形平滑填充glShadeMo

18、del(GL_SMOOTH);glBegin(GL_TRIANGLES);glColor3f(0.0, 0.0, 1.0);glPointSize(5.0);glVertex2f(0.3, 0.3);glColor3f(1.0, 0.0, 0.0);glPointSize(5.0);glVertex2f(0.4, 0.6);glColor3f(1.0, 1.0, 0.0);glPointSize(5.0);glVertex2f(0.5, 0.4); glEnd();5. 调用glPolygonMode(face, displayMode);glPolygonMode(GL_FRONT_AND_

19、BACK, GL_LINE);6. 两个正方形混合(1)glEnable(GL_BLEND);glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);/混合glColor4f(0.0, 1.0, 0.0,0.5); / Set current color to greenglRectf(0.6, 0.3, 0.2, 0.8);int vertex1 = 0.6, 0.3 ;int vertex2 = 0.2, 0.8 ;glRectiv(vertex1, vertex2); glColor4f(0.0, 0.0, 1.0,0.5); / Set cur

20、rent color to green glRectf(0.5, 0.2, 0.1, 0.5); int vertex3 = 0.5, 0.2 ; int vertex4 = 0.1, 0.5 ; glRectiv(vertex3, vertex4);(2)glEnable(GL_BLEND);glBlendFunc(GL_SRC_ALPHA,GL_ZERO);(3) glEnable(GL_BLEND);glBlendFunc(GL_ONE,GL_ZERO);说明:用函数glBlendFunc(sFactor,dFactor);选择调和因子的值产生不同的混合效果,有GL_ONE,GL_ZER

21、O,GL_SRC_ALPHA GL_DST_ALPHA,GL_ONE_MINUS_SRC_ALPHA等实验三1. 平移 glMatrixMode(GL_MODELVIEW); glColor3f(1.0, 1.0, 0.0); glRectf(0.6, 0.3, 0.2, 0.8);glColor3f(1.0, 0.0, 0.0);glTranslatef(-0.5,-0.3,0.0);glRectf(0.6, 0.3, 0.2, 0.8);旋转:glColor3f(1.0, 1.0, 0.0); glRectf(0.6, 0.3, 0.2, 0.8)glLoadIdentity();glRo

22、tatef(90.0,0.0,0.0,1.0); glRectf(0.6, 0.3, 0.2, 0.8); 缩放:glColor3f(0.0, 1.0, 1.0);glLoadIdentity();glScalef(-0.5, 1.0, 1.0);glRectf(0.6, 0.3, 0.2, 0.8);3.桌子绘制void table()glColor3f(0.0, 1.0, 1.0);glRectf(-0.5, 0.3, 0.5, -0.3);glColor3f(1.0, 1.0, 0.0);glRectf(-0.4, 0.25, 0.4, 0.15);glColor3f(1.0, 1.0,

23、 0.0);glRectf(-0.4, 0.25, -0.3, -0.15);glColor3f(1.0, 1.0, 0.0);glRectf(0.3, 0.25, 0.4, -0.15);glColor3f(1.0, 1.0, 0.0);glRectf(-0.4, -0.15, 0.4, -0.25);glColor3f(1.0, 0.2, 0.0);glRotatef(-45.0, 0.0, 0.0, 1.0);glTranslatef(0.15, 0.35, 0.0);glRectf(-0.3, -0.15, 0.3, -0.25);glLoadIdentity();glColor3f(

24、1.0, 0.2, 0.0);glRotatef(-90, 0.0, 0.0, 1.0);glTranslatef(-0.35, -0.15, 0.0);glRectf(-0.3, -0.15, 0.3, -0.25);glLoadIdentity();glColor3f(1.0, 0.2, 0.0);glRotatef(-90, 0.0, 0.0, 1.0);glTranslatef(-0.65, 0.15, 0.0);glRectf(-0.3, -0.15, 0.3, -0.25);glLoadIdentity();glColor3f(1.0, 0.2, 0.0);glRotatef(-9

25、0, 0.0, 0.0, 1.0);glTranslatef(-0.2, 0.6, 0.0);glRectf(-0.3, -0.15, 0.3, -0.25);void display() glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); / Clear the frame bufferglMatrixMode(GL_MODELVIEW);glPushMatrix();glRotatef(-45.0, 0.0, 0.0, 1.0);table();glPopMatrix(); glFlush(); 4. 编程绘制罗马字母和。:void word

26、()glColor3f(1.0, 1.0, 1.0);glBegin(GL_LINES);glVertex2f(-0.25, 0.3);glVertex2f(-0.2, 0.3); glEnd();glColor3f(1.0, 1.0, 1.0);glBegin(GL_LINES);glVertex2f(-0.25, 0.0);glVertex2f(-0.15, 0.0);glEnd();glColor3f(1.0, 1.0, 1.0);glBegin(GL_LINES);glVertex2f(-0.2, 0.0);glVertex2f(-0.2, 0.3);glEnd();glColor3f

27、(1.0, 1.0, 1.0);glBegin(GL_LINES); glVertex2f(-0.2, 0.3);glVertex2f(-0.1, 0.3);glEnd();glColor3f(1.0, 1.0, 1.0);glBegin(GL_LINES);glVertex2f(0.1, 0.3);glVertex2f(0.2, 0.3);glEnd();void lines()glMatrixMode(GL_MODELVIEW);glLoadIdentity();glColor3f(1.0, 1.0, 1.0);glRotatef(30, 0.0, 0.0, 1.0);glTranslat

28、ef(0.03, 0.04, 0.0);glRectf(-0.01, 0.3, 0, 0); glLoadIdentity();glColor3f(1.0, 1.0, 1.0);glRotatef(-30, 0.0, 0.0, 1.0);glTranslatef(-0.03, 0.04, 0.0); glRectf(0.01, 0.3, 0, 0);:void lines()glMatrixMode(GL_MODELVIEW);glLoadIdentity();glColor3f(1.0, 1.0, 1.0);glRotatef(28, 0.0, 0.0, 1.0);glTranslatef(

29、0.03, 0.0, 0.0);glRectf(-0.01, 0.35, 0, -0.35); glLoadIdentity(); glColor3f(1.0, 1.0, 1.0); glRotatef(-28, 0.0, 0.0, 1.0); glTranslatef(-0.03, 0.0, 0.0); glRectf(0.01, 0.35, 0, -0.35);void word()glMatrixMode(GL_MODELVIEW);glColor3f(1.0, 1.0, 1.0);glBegin(GL_LINES);glVertex2f(-0.2, 0.32);glVertex2f(-

30、0.1, 0.32);glBegin(GL_LINES);glVertex2f(0.1, 0.32);glVertex2f(0.2, 0.32);glEnd();void display() glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); / Clear the frame bufferglPushMatrix();glScalef(1.0, -1.0, 1.0);word();glScalef(1.0, -1.0, 1.0);word();lines();glPopMatrix();glFlush();实验四1. 绘制房子void resh

31、ape(int w, int h)glViewport(0, 0, w, h);glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(-3.0, 3.0, -3.0, 3.0, -3.0, 3.0);void display()glClear(GL_COLOR_BUFFER_BIT); / Clear the frame bufferglMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);glutSwa

32、pBuffers();glShadeModel(GL_FLAT);glColor3f(1.0, 1.0, 1.0);glBegin(GL_LINE_LOOP); glVertex3f(0.4, -0.4,-0.4); glVertex3f(0.4, 0.2, -0.4);glVertex3f(0, 0.4, -0.4); glVertex3f(-0.4, 0.2, -0.4); glVertex3f(-0.4, -0.4, -0.4);glEnd();glColor3f(1.0, 1.0, 1.0);glBegin(GL_LINE_LOOP); glVertex3f(0.5, -0.4, 0.

33、6); glVertex3f(0.4, 0.2, 0.4);glVertex3f(0, 0.4, 0.4); glVertex3f(-0.4, 0.2, 0.4); glVertex3f(-0.3, -0.4, 0.5);glEnd();glColor3f(1.0, 1.0, 1.0);glBegin(GL_LINES); /CyanglVertex3f(0.4, -0.4, -0.4); glVertex3f(0.5, -0.4, 0.6);glVertex3f(0.4, 0.2, -0.4); glVertex3f(0.4, 0.2, 0.4);glVertex3f(0, 0.4, -0.

34、4); glVertex3f(0, 0.4, 0.4);glVertex3f(-0.4, 0.2, -0.4); glVertex3f(-0.4, 0.2, 0.4);glVertex3f(-0.4, -0.4, -0.4); glVertex3f(-0.3, -0.4, 0.5);glEnd();glFlush();2.void init()glClear(GL_COLOR_BUFFER_BIT);glMatrixMode(GL_MODELVIEW);gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);glMatrixMode(GL_

35、MODELVIEW);glFrustum(-0.4, 0.5, -0.2, 0.2, -0.2, 0.6);实验五1.1.1 删除代码glEnable(GL_LIGHT0);/the earth/*glPushMatrix();glTranslatef(RAD*cos(theta), RAD*sin(theta), 0.);glRotatef(23.5, 0., 1., 0.);glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, pink);glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pink);glMateria

36、lfv(GL_FRONT_AND_BACK, GL_SPECULAR, light0_color);glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);glLineWidth(2.);glBegin(GL_LINES);glVertex3f(0., 0., .5);glVertex3f(0., 0., -.5);glEnd();glScalef(.33, .33, .33);glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, cyan);glMaterialfv(GL_FRONT_AND_

37、BACK, GL_DIFFUSE, cyan);glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, light0_color);glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);gluSphere(Q2, 1., 50, 50);glPopMatrix();*/the earth's equatorial plane/*glPushMatrix();glTranslatef(RAD*cos(theta), RAD*sin(theta), 0.);glRotatef(23.5,

38、0., 1., 0.);glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, clear);glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, clear);glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, light0_color);glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);glBegin(GL_QUADS);glVertex3f(-5.*D, -D, 0.);glVertex3f(5.*D, -D, 0

39、.);glVertex3f(5.*D, D, 0.);glVertex3f(-5.*D, D, 0.);glEnd();glPopMatrix();*/1.2关闭光照glDisable(GL_LIGHTING);1.3去除太阳的光照处理(LIGHT1)和着色处理,观察效果1.4 基于1.1,使用以下代码,观察全局环境光的效果:glLightfv(GL_LIGHT1, GL_POSITION, light1_position );glLightfv(GL_LIGHT1, GL_AMBIENT, ambient_color );glLightModelfv(GL_LIGHT_MODEL_AMBIE

40、NT,black);glEnable(GL_LIGHT1); 1.5基于1.1,使用以下代码观察效果:glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, white );glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, black );1.6基于1.1,局部环境光设置为红色,环境光材质设为蓝色,观察效果;GLfloat ambient_color = 1.0, 0.0, 0.0, 1.0 ;/局部环境光glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,blue);/环境光材质1.7基于

41、1.1,只打开漫反射的效果,改变光源1的位置,观察漫反射角度对光照效果的影响;GLfloat light1_position = 1.0, 5.0, 10.0, 0.0 ; glLightfv(GL_LIGHT1, GL_POSITION, light1_position);glLightfv(GL_LIGHT1, GL_SPECULAR, light1_color);glShadeModel(GL_FLAT);glLightfv(GL_LIGHT1, GL_POSITION, light1_position);glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_c

42、olor);1.8基于1.1,只打开镜面反射的效果,分别进行以下设置,观察镜面反射角度对光照效果的影响(将光泽度值设置小一些)l 只改变光源1的位置GLfloat mat_shininess = 15.0 ;glLightfv(GL_LIGHT1, GL_POSITION, light1_position);glLightfv(GL_LIGHT1, GL_SPECULAR, light1_color);glEnable(GL_LIGHT1);glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, light0_color);glMaterialfv(GL_FR

43、ONT_AND_BACK, GL_SHININESS, mat_shininess);l 只改变视点的位置gluLookAt(0.0, 50.0, 3.0, 2.0, 3.0, -1.0, 0.0, 0.0, 1.0);l 同时改变光源1和视点的位置1.9基于1.1,为光源1定义聚光灯,并调整3个参数,观察光照效果(参数为GL_SPOT_DIRECTION,GL_SPOT_CUTOFF,GL_SPOT_EXPONENT,;1.10基于1.1,建立光线衰减模型,分别调整常量、一次和二次衰减参数(参数为GL_CONSTANT_ATTENUATION、GL_LINEAR_ATTENUATION、GL

44、_QUADRATIC_ATTENUATION),观察光照效果;GLfloat spot_direction = 0.0, 0.0, -1.0 ;glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spot_direction);glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 50.0);glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 2.5);1.11基于1.1,分别使用GL_FLAT和GL_SMOOTH,观察这两种不同着色处理,并分析;GL_FLAT:GL_SMOOTH:前者是使用线性插值方式填充,后者是默认为填

45、充的颜色。实验六1. 参照texture1.c的例子,在Photoshop生成一幅2D纹理图,并映射在立方体表面;2. #include <stdlib.h>3. #include <stdio.h>4. #include <math.h>5.6. void myinit(void);7. void makeImage(void);8.9.10. /* 读取纹理 */11.12. #define TEX_WIDTH 25613. #define TEX_HEIGHT 25614. GLubyte texImageTEX_WIDTHTEX_HEIGHT3;15

46、.16. void readTexture(void)17. 18. FILE *fd;19. GLubyte ch;20. int i, j, k;21.22. fd = fopen("HongKong.256.256.raw", "rb");23. for (i = 0; i<TEX_WIDTH; i+) / for each row24. 25. for (j = 0; j<TEX_HEIGHT; j+) / for each column26. 27. for (k = 0; k<3; k+) / read RGB compon

47、ents of the pixel28. 29. fread(&ch, 1, 1, fd);30. texImageijk = (GLubyte)ch;31. 32. 33. 34. fclose(fd);35. 36.37. void myinit(void)38. 39. glClearColor(0.0, 0.0, 0.0, 0.0);40. glEnable(GL_DEPTH_TEST);41. glDepthFunc(GL_LESS);42.43. readTexture();44. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);45.46. /

48、* 定义纹理 */47. glTexImage2D(GL_TEXTURE_2D, 0, 3, TEX_WIDTH,48. TEX_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, &texImage000);49.50. /* 控制滤波 */51. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);52. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);53. glTexParameterf(GL_TEXTURE_2D,

49、GL_TEXTURE_MAG_FILTER, GL_NEAREST);54. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);55.56. /* 说明映射方式*/57. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);58.59. /* 启动纹理映射 */60. glEnable(GL_TEXTURE_2D);61.62. glShadeModel(GL_FLAT);63. 64.65. void display(void)66. 67. glC

50、lear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);68.69. /* 设置纹理坐标和物体几何坐标 */70. glBegin(GL_QUADS);71. glTexCoord2f(1.0, 1.0); glVertex3f(-2.0, -1.0, 0.0);72. glTexCoord2f(1.0, 0.0); glVertex3f(-2.0, 1.0, 0.0);73. glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 1.0, 0.0);74. glTexCoord2f(0.0, 1.0); glVertex3f(

51、0.0, -1.0, 0.0);75.76. glTexCoord2f(0.0, 0.0); glVertex3f(1.0, -1.0, 0.0);77. glTexCoord2f(0.0, 1.0); glVertex3f(1.0, 1.0, 0.0);78. glTexCoord2f(1.0, 1.0); glVertex3f(2.41421, 1.0, -1.41421);79. glTexCoord2f(1.0, 0.0); glVertex3f(2.41421, -1.0, -1.41421);80. glEnd();81.82. glutSwapBuffers();83. 84.8

52、5. void reshape(GLsizei w, GLsizei h)86. 87. glViewport(0, 0, w, h);88. glMatrixMode(GL_PROJECTION);89. glLoadIdentity();90. gluPerspective(60.0, 1.0*(GLfloat)w / (GLfloat)h, 1.0, 30.0);91. glMatrixMode(GL_MODELVIEW);92. glLoadIdentity();93. glTranslatef(0.0, 0.0, -3.6);94. 95.96. int main(int argc, char* argv)97. 98. / Standard GLUT initialization99. glutInit(&argc, argv);100. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);101. glutInitWindowSize(500, 500);102. glutInitWindowPosition(70, 70);103. glutCreateWindow("A white cube with three colored l

温馨提示

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

最新文档

评论

0/150

提交评论