三维图形学实验报告.pdf
《三维图形学实验报告.pdf》由会员分享,可在线阅读,更多相关《三维图形学实验报告.pdf(35页珍藏版)》请在咨信网上搜索。
1、实验1.(1)三角形:ftinclude /glut,h includes gl.h and glu.h void init(void)glClearColor(0.0,0.0,0.0,0.0);void reshape(int w,int h)glV iewport(0,0,(GLsizei)w,(GLsizei)h);glMatrixMode(GL_PROJECTI ON);/指定哪一个矩阵是当前矩阵 glLoadI dentity();重置当前指定的矩阵为单位矩阵。glu0rtho2D(-l.0,1.0,-1.0,1.0);/The para are:(left,right,bottom
2、,top)定义二 维正交投影矩阵glMatrixMode(GL_MODELV I EW);指定哪一个矩阵是当前矩阵)void display(void)(g1C1ear(GL_COLOR_B UFFER_B I T);/Clear the frame buffer glColor3f(0.0,1.0,0.0);/Set current color to green glB egin(GLPOLY GON);/Draw the triangle glV ertex2f(-0.7,-0.7);glV ertex2f(0.7,-0.7);glV ertex2f(0,0.7);glEndO;glFlu
3、sh();/Force to display the new drawings immediately int main(int argc,char*argv)glutlnit(&argc,argv);/I nitialize GLUT function callings glutlnitWindowSize(400,400);glutI nitWindowPosition(200,100);/in numbers of pixels glutCreateWindow(,zGreen Triangle);glutDisplayFunc(display);/is created or re-dr
4、ew init();/I nvoke this function for initialization glutMainLoopO;/Enter the event processing loop return 0;/I ndicate normal termination/(Required by ANSI C)/操作,定义事件回调函数(2)点:void display()glClear(GL_COLOR_B UFFER_B I T);/Clear the frame buffer glColor3f(0.0,1.0,0.0);/Set current color to green glPo
5、intSize(10.);glB egin(GL_POI NTS);glV ertex2i(0.5,0.5);glEndO;glFlush();/Force to display the new drawings immediately(3)线段:void display()glClear(GL_COLOR_B UFFER_B I T);/Clear the frame buffer glColor3f(0.0,1.0,0.0);/Set current color to green glLineWidth(3.0);glB egin(GL_LI NES);glV ertex3f(0.,0.,
6、0.);glV ertex3f(0.,1.,0.);glEndO;glFlush();/Force to display the new drawings immediately(4)四边形:void display()glClear(GL_COLOR_B UFFER_B I T);/Clear the frame buffer glColor3f(1.0,0.0,0.0);/Set current color to green glRectf(0.6,0.3,0.2,0.8);int vertexl =0.6,0.3;int vertex2=0.2,0.8;glRectiv(vertexl,
7、vertex2);glFlushO;/Force to display the new drawings immediately2.立方体:3.void reshape(int w,int h)4.(5.glV iewport(0,0,w,h);6.glMatrixMode(GL_PR0JECTI 0N);7.glLoadldentity();8.gl0rtho(-3.0,3.0,-3.0,3.0,-3.0,3.0);9.)10.void display()11.glClear(GL_COLOR_B UFFER_B I T);/Clear the frame buffer12.glMatrix
8、Mode(GL_MODELV I EW);13.glLoadldentity();14.gluLookAt(l.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0);15.glutWireCube(0.5);16.glutSwapB uffers();17.glColor3f(0.0,1.0,0.0);18.glB egin(GL_LI NE_LOOP);/Green19.glV ertex3f(0.,0.,0.);glV ertex3f(0.,2,0.);20.glV ertex3f(2,2,0.);glV ertex3f(2,0.,0.);21.glEndO;22.glCo
9、lor3f(l.0,1.0,0.0);23.glB egin(GL_LI NE_LOOP);/Y ellow24.glV ertex3f(0.,0.,2);glV ertex3f(2,0.,2);25.glV ertex3f(2,2,2);glV ertex3f(0.,2,2);26.glEnd();27.glColor3f(0.0,1.0,1.0);28.glB egin(GL_LI NES);/Cyan29.glV ertex3f(0.,0.,0.);glV ertex3f(0.,0.,2);30.glV ertex3f(0.,2,0.);glV ertex3f(0.,2,2);31.gl
10、V ertex3f(2,0.,0.);glV ertex3f(2,0.,2);32.glV ertex3f(2,2,0.);glV ertex3f(2,2,2);33.glEnd();34.glFlush();/Force to display the new drawings immediately3.(1)三角形条带void display()glClear(GL_COLOR_B UFFER_B I T);/Clear the frame bufferGLfloat v0=0.,0.3,vlLJ=0.2,0.6,v2口=0.4,0.3,v3=0.5,0.6),v4口=0.6,0.3),v5
11、口=0.8,0.6),glColor3f(1.0);glB egin(GL_TRI ANGLE_STRI P);三角形条带函数glV ertex2fv(vO);glV ertex2fv(vl);glV ertex2fv(v2);glV ertex2fv(v3);glV ertex2fv(v4);glV ertex2fv(v5);glEndO;glFlush();/Force to display the new drawings immediately3.(2)三角形扇形GLfloat v0=0.,0.3,vl=0.3,0.7,v2=0.5,0.65,v3=0.5,0.5,v4口=0.45,0
12、.4),v5=0.3,0.35,glColor3f(l.0);glB egin(GL_TRI ANGLE_FAN);共享一个顶点glV ertex2fv(vO);glV ertex2fv(vl);glV ertex2fv(v2);glV ertex2fv(v3);glV ertex2fv(v4);glV ertex2fv(v5);glEndO;glFlush();/Force to display the new drawings immediately实验二L点glColor3f(0.0,1.0,0.0);glPointSize(3.);glB egin(GL_POI NTS);glV er
13、tex3f(0.1,0.5,0);glColor3f(l.0,1.0,0.0);glPointSize(5.);glB egin(GL_POI NTS);glV ertex3f(0.5,0.5,0);glColor3f(l.0,0.0,0.0);glPointSize(10.);glB egin(GL_POI NTS);glV ertex3f(0.3,0,4,0);glColor3f(0.0,0.0,1.0);glPointSize(1.);glB egin(GL_POI NTS);glV ertex3f(0.2,0.6,0);glColor3f(l.0,1.0,1.0);glPointSiz
14、e(4.);glB egin(GL_POI NTS);glV ertex3f(0.3,0.5,0);glEndO;glFlushO;/Force to display the new drawings immediately2.直线glColor3f(0.0,1.0,0.0);glLineWidth(l.0);glB egin(GL_LI NES);glV ertex3f(0.3,0.1,0.0);glV ertex3f(0.3,0.5,0.0);垂直距离glColor3f(l.0,1.0,0.0);glLineWidth(3.);宽度glB egin(GL_LI NES);glV ertex
15、3f(0.2,0.1,0.0);glV ertex3f(0.2,0.5,0.0);glColor3f(l.0,0.0,0.0);glLineWidth(5.);glB egin(GL_LI NES);glV ertex3f(0.5,0.1,0.0);glV ertex3f(0.5,0.5,0.0);glEndO;glFlushO;/Force to display the new drawings immediately3.直线,虚线,点划线glColor3f(l.0,0.0,0.0);glLineWidth(2.0);glB egin(GL_LI NES);glV ertex2f(0.0,0
16、.3);glV ertex2f(0.8,0.3);glEndO;glColor3f(l.0,0.0,0.0);glEnable(GL_LI NE_STI PPLE);glLineStipple(1,0 x0101);glLineWidth(2.0);glB egin(GL_LI NES);glV ertex2f(0.0,0.5);glV ertex2f(0.8,0.5);glEndO;glColor3f(l.0,0.0,0.0);glEnab1e(GL_LI NE_STIPPLE);glLineStipple(l,Oxffcc);glLineWidth(2.0);glB egin(GL_LI
17、NES);glV ertex2f(0.0,0.8);glV ertex2f(0.8,0.8);glEndO;4.顶点不同颜色的三角形平滑填充glShadeModel(GL_SM00TH);glB egin(GL_TRI ANGLES);glColor3f(0.0,0.0,1.0);glPointSize 0);glV ertex2f(0.3,0.3);glColor3f(l.0,0.0,0.0);glPointSize 0);glV ertex2f(0.4,0.6);glColor3f(l.0,1.0,0.0);glPointSize 0);glV ertex2f(0.5,0.4);glEnd
18、O;5.调用 glPolygonMode(face,di splay Mode);glPolygonMode(GL_FR0NT_AND_B ACK,GLLI NE);6.两个正方形混合(1)glEnable(GL_B LEND);glB lendFunc(GL_SRC_ALPH A,GL_ONE_MI NUS_SRC_ALPH A);混合glColor4f(0.0,1.0,0.0,0.5);/Set current color to greenglRectf(0.6,0.3,int vertexl=int vertex2=glRectiv(vertexl,0.2,0.8);0.6,0.3;0.
19、2,0.8;vertex2);glColor4f(0.0,0.0,1.0,0.5);/Set current 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)3 line|o回 汉glEnable(GL_B LEND);glB lendFunc(GL_SRC_ALPH A,GL_ZERO);glEnable(GLB LEND);glB lendFunc(GL_ONE,GL_ZERO);说明:用函数glB lendFunc(
20、sFactor,dFactor);选择调和因子的值产生不同的混合效果,有GL_0NE,GL_ZERO,GL_SRC_ALPH AGL_DST_ALPH A,GL_ONE_MI NUS_SRC_ALPH A等实验三1.平移glMatrixMode(GL_MODELV I EW);glColor3f(l.0,1.0,0.0);glRectf(0.6,0.3,0.2,0.8);glColor3f(l.0,0.0,0.0);glTranslatef(-0.5,-0.3,0.0);glRectf(0.6,0.3,0.2,0.8);旋转:glColor3f(l.0,1.0,0.0);glRectf(0.6
21、,0.3,0.2,0.8)glLoadldentity();glRotatef(90.0,0.0,0.0,1.0);glRectf(0.6,0.3,0.2,0.8);缩放:glColor3f(0.0,1.0,1.0);glLoadldentity();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(l.0,1.0,glRectf(-0.4,0.25,glColor3f(l.0,1.0,glRe
22、ctf(-0.4,0.25,0.0);0.4,0.15);0.0);-0.3,-0.15);glColor3f(l.0,1.0,0.0);glRectf(0.3,0.25,0.4,-0.15);glColor3f(l.0,1.0,0.0);glRectf(-0.4,-0.15,0.4,-0.25);glColor3f(l.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);glLoadldentity();glColor3f(l.0,0.2,0.0);
23、glRotatef(-90,0.0,0.0,1.0);glTranslatef(-0.35,-0.15,0.0);glRectf(-0.3,-0.15,0.3,-0.25);glLoadldentity();glColor3f(l.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);glLoadldentity();glColor3f(l.0,0.2,0.0);glRotatef(-90,0.0,0.0,1.0);glTranslatef(-0.2,0.
24、6,0.0);glRectf(-0.3,-0.15,0.3,-0.25);void display()glClear(GL_COLOR_B UFFER_B I T|GL_DEPTH _B UFFER_B I T);/Clear the frame buffer glMatrixMode(GL_MODELV I EW);glPushMatrix();glRotatef(-45.0,0.0,0.0,1.0);table();glPopMatrix();glFlushO;4.编程绘制罗马字母IV和X。IV:void word()glColor3f(1.0,1.0,1.0);glB egin(GL_L
25、I NES);glV ertex2f(-0.25,0.3);glV ertex2f(-0.2,0.3);glEndO;glColor3f(l.0,1.0,1.0);glB egin(GL_LI NES);glV ertex2f(-0.25,0.0);glV ertex2f(-0.15,0.0);glEndO;glColor3f(l.0,1.0,1.0);glB egin(GL_LI NES);glV ertex2f(-0.2,0.0);glV ertex2f(-0.2,0.3);glEndO;glColor3f(l.0,1.0,1.0);glB egin(GL_LI NES);glV erte
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 三维 图形学 实验 报告
1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前自行私信或留言给上传者【曲****】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时私信或留言给本站上传会员【曲****】,需本站解决可联系【 微信客服】、【 QQ客服】,若有其他问题请点击或扫码反馈【 服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【 版权申诉】”(推荐),意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:4008-655-100;投诉/维权电话:4009-655-100。