《第三章 基本图形的绘制精选PPT.ppt》由会员分享,可在线阅读,更多相关《第三章 基本图形的绘制精选PPT.ppt(36页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、第三章基本图形的绘制第1页,本讲稿共36页实例02绘制基本图形第2页,本讲稿共36页坐标用户(opengl)坐标第3页,本讲稿共36页填充模式glPolygonMode(GL_FRONT,GL_FILL);/设置正面为填充方式glPolygonMode(GL_BACK,GL_LINE);/设置反面为边缘绘制方式glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);/设置两面均为顶点绘制方式glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);/设置两面均为顶点绘制方式glPolygonMode(GL_FRONT_AND_BACK,GL
2、_POINT);/设置两面均为顶点绘制方式第4页,本讲稿共36页glFrontFace(GL_CCW);/设置CCW方向为“正面”,CCW即CounterClockWise,逆时针glFrontFace(GL_CW);/设置CW方向为“正面”,CW即ClockWise,顺时针第5页,本讲稿共36页如何绘图glBegin(GL_LINES);glVertex2f(0.0,0.0);glVertex2f(0.0,3.0);glVertex2f(3.0,3.0);glVertex2f(4.0,1.5);glVertex2f(3.0,0.0);glEnd();基本图形类型组织基本图形的顶点第6页,本讲
3、稿共36页顶点的其它组成方式glBegin(primType);for(i=0;i n;+i)glColor3f(redi,greeni,bluei);glVertex3fv(coordsi);glEnd();第7页,本讲稿共36页第8页,本讲稿共36页Geometric PrimitivesGL_POINTS单个顶点集GL_LINES多组双顶点线段GL_POLYGON单个简单填充凸多边形GL_TRIANGLES多组独立填充三角形GL_QUADS多组独立填充四边形GL_LINE_STRIP不闭合折线GL_LINE_LOOP闭合折线GL_TRIANGLE_STRIP线型连续填充三角形串GL_TR
4、IANGLE_FAN扇形连续填充三角形串GL_QUAD_STRIP连续填充四边形串第9页,本讲稿共36页基本图例第10页,本讲稿共36页Howtobuildstripshape?GL_TRIANGLE_FANVertices1,n+1,andn+2definetrianglen.GL_TRIANGLE_STRIPForoddnforn,n+1,andn+2definetrianglen.Forevennforn+1,n,andn+2definetrianglen.第11页,本讲稿共36页Howtobuildstripshape?(Cont.)GL_QUAD_STRIPVertices2n-1,
5、2n,2n+2,and2n+1definequadriliteraln.N/2-1quadriliteralsaredrawn.第12页,本讲稿共36页Shapes sample第13页,本讲稿共36页练习01圆柱的绘制思路第14页,本讲稿共36页练习02绘制连续多边形思路第15页,本讲稿共36页练习03小房子的绘制思路线框模式实体模式点模式深度测试第16页,本讲稿共36页构建复杂图形顶点数组第17页,本讲稿共36页Vertexarrayvoid glVertexPointer(GLint size,GLenum type,GLsizei stride,const GLvoid*pointer
6、);pointertype GL_SHORT,GL_INT,GL_FLOAT,GL_DOUBLEsize 2,3,or 4.stride offset between consecutive vertexes.第18页,本讲稿共36页void glIndexPointer(GLenum type,GLsizei stride,const GLvoid*pointer);void glColorPointer(GLint size,GLenum type,GLsizei stride,const GLvoid*pointer);void glNormalPointer(GLenum type,G
7、Lsizei stride,const GLvoid*pointer);第19页,本讲稿共36页void glEnableClientState(GLenum array)GL_VERTEX_ARRAY,GL_COLOR_ARRAY,GL_INDEX_ARRAY,GL_NORMAL_ARRAY,GL_TEXTURE_COORD_ARRAY,GL_EDGE_FLAG_ARRAY第20页,本讲稿共36页void glArrayElement(GLint ith)void glDrawElements(GLenum mode,GLsizei count,GLenum type,void*indice
8、s);inti;glBegin(mode);for(i=0;icount;i+)glArrayElement(indicesi);glEnd();第21页,本讲稿共36页glArrayElementglEnableClientState(GL_COLOR_ARRAY);glEnableClientState(GL_VERTEX_ARRAY);glColorPointer(3,GL_FLOAT,0,colors);glVertexPointer(2,GL_INT,0,vertices);glBegin(GL_TRIANGLES);glArrayElement(2);glArrayElement(
9、3);glArrayElement(5);glEnd();第22页,本讲稿共36页EqualcodeglBegin(GL_TRIANGLES);glColor3fv(colors+(2*3*sizeof(GLfloat);glVertex3fv(vertices+(2*2*sizeof(GLint);glColor3fv(colors+(3*3*sizeof(GLfloat);glVertex3fv(vertices+(3*2*sizeof(GLint);glColor3fv(colors+(5*3*sizeof(GLfloat);glVertex3fv(vertices+(5*2*sizeo
10、f(GLint);glEnd();第23页,本讲稿共36页staticGLubytefrontIndices=4,5,6,7;staticGLubyterightIndices=1,2,6,5;staticGLubytebottomIndices=0,1,5,4;staticGLubytebackIndices=0,3,2,1;staticGLubyteleftIndices=0,4,7,3;staticGLubytetopIndices=2,3,7,6;glDrawElements(GL_QUADS,4,GL_UNSIGNED_BYTE,frontIndices);glDrawElement
11、s(GL_QUADS,4,GL_UNSIGNED_BYTE,rightIndices);glDrawElements(GL_QUADS,4,GL_UNSIGNED_BYTE,bottomIndices);glDrawElements(GL_QUADS,4,GL_UNSIGNED_BYTE,backIndices);glDrawElements(GL_QUADS,4,GL_UNSIGNED_BYTE,leftIndices);glDrawElements(GL_QUADS,4,GL_UNSIGNED_BYTE,topIndices);第24页,本讲稿共36页staticGLubyteallInd
12、ices=4,5,6,7,1,2,6,5,0,1,5,4,0,3,2,1,0,4,7,3,2,3,7,6;glDrawElements(GL_QUADS,24,GL_UNSIGNED_BYTE,allIndices);第25页,本讲稿共36页Set ColorTheOpenGLColorModelOpenGLusestheRGB(A)colormodelThereisalsoacolor-indexmodeColorsarespecifiedasfloating-pointnumbersintherange0.0,1.0setawindowsbackgroundcolor,shouldcall
13、 glClearColor(1.0,0.3,0.6,1.0);R G B A-Tosetacolor,shouldcall glColor3f(1.0,0.3,0.6);第26页,本讲稿共36页ColormodelOpenGL使用RGB(A)颜色模型voidglColor3bsifdubusui(TYPEr,TYPEg,TYPEb);voidglColor4bsifdubusui(TYPEr,TYPEg,TYPEb,TYPEa);voidglColor3bsifdubusuiv(TYPE*v);voidglColor4bsifdubusuiv(TYPE*v);颜色索引模式voidglIndex
14、sifd(TYPEc);voidglIndexsifdv(TYPE*c);第27页,本讲稿共36页OpenGLColorSpecifyingSchemeset_current_color(red);draw_object(A);draw_object(B);set_current_color(green);set_current_color(blue);draw_object(C);Color buffer Color buffer?第28页,本讲稿共36页Clearing the WindowglClearColor(0.0,0.0,0.0,0.0);glClearDepth(1.0);gl
15、Clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glClearColor(0.0,0.0,0.0,0.0);glClear(GL_COLOR_BUFFER_BIT);第29页,本讲稿共36页Displaying Points,LinesPoint Detailsvoid glPointSize(GLfloat size);Line Detailsvoid glLineWidth(GLfloat width);The line width can be got by calling:glGetFloatv(GL_LINE_WIDTH_RANGE);S
16、tippled LinesglLineStipple(1,0 x3F07);void glLineStipple(GLint factor,GLushort pattern);0011111100000111Redbook:lines.c第30页,本讲稿共36页Stippling Polygonsvoid glPolygonStipple(const GLubyte*mask);状态开关glEnable(GL_POLYGON_STIPPLE);glDisable(GL_POLYGON_STIPPLE);glEnable(GL_LINE_STIPPLE);glDisable(GL_LINE_ST
17、IPPLE);第31页,本讲稿共36页Polys.c第32页,本讲稿共36页深度测试显示模式支持深度缓冲glEnable(GL_DEPTH_TEST)参见实例“深度测试”第33页,本讲稿共36页调研与讨论1.列举比较常用光栅扫描算法2.列举比较常用填充算法3.列举比较常用消隐算法4.列举比较常用反走样技术5.列举比较常用裁剪算法分组讨论第34页,本讲稿共36页实验01绘制基本图形提交格式:把实验报告(word文档)和工程文件打包,并以学号姓名(如:20080001郭德刚)的形式命名。提交位置:ftp:/202.113.72.6/学生作业/汪日伟/作业及实验报告/2008-2009第二学期图形学/第一次实验提交时间:2009-3-16前第35页,本讲稿共36页实验02多边形的填充多边形的填充提交格式:把实验报告(word文档)和工程文件打包,并以学号姓名(如:20080001郭德刚)的形式命名。提交位置:ftp:/202.113.72.6/学生作业/汪日伟/作业及实验报告/2008-2009第二学期图形学/第一次实验提交时间:2009-3-23前第36页,本讲稿共36页
限制150内