ImageVerifierCode 换一换
格式:PPT , 页数:55 ,大小:1.07MB ,
资源ID:379293      下载积分:2000 积分
快捷下载
登录下载
邮箱/手机:
温馨提示:
如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝扫码支付 微信扫码支付   
注意:如需开发票,请勿充值!
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【http://www.mydoc123.com/d-379293.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(CAP 4703Computer Graphic Methods.ppt)为本站会员(hopesteam270)主动上传,麦多课文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文库(发送邮件至master@mydoc123.com或直接QQ联系客服),我们立即给予删除!

CAP 4703Computer Graphic Methods.ppt

1、CAP 4703 Computer Graphic Methods,Prof. Roy Levow Lecture 2,2-Dimensional Drawing with OpenGL,Two-dimensional objects are a special case of three-dimensional figures The drawing is limited (by the programmer) to a plane Viewing is normally an orthogonal view, perpendicular to the drawing plane,Sierp

2、inski Gasket,A simple but interesting example Start with any triangle Pick an internal point at random Pick a vertex at random Find the midpoint between 1 and 2 Display this point Replace initial point with this one Repeat from step 2,Sierpinski Gasket Construction,OpenGL Program for Sierpinski Gask

3、et,main() initialize_the_system();for (some_number_of_points)pt = generate_a_point();display_the_point(pt);cleanup();return 0; ,Points or Vertices,Points are represented by vectors with an entry for each coordinatep = (x, y, z) in 3 dimensionsp = (x, y, 0) gives 2 dimensions by always setting z to 0

4、 OpenGL allows up to 4 dimensions Internal representation is always the same,OpenGL Vertices,Vertex creating functions have general nameglVertex*The suffix is 2 or 3 characters Number of dimensions: 2, 3, or 4 Data type: i = integer, f = float, d = double Optional v if pointer,Underlying Representat

5、ion,OpenGL data types are defined in header file#define GLfloat float so a header might look likeglVertex2i(GLint xi, GLint yi) orglVertex3f(GLfloat xf, GLfloat yf,GLfloat zf),Representation (cont.),For the vector formGLfloat vertex3; and then useglVertex3fv(vertex);,Defining Geometric Objects,Objec

6、ts are defined by collections of point constructors bounded by calls to glBegin and glEnd A line is defined byglBegin(GL_LINES);glVertex2f(x1, y1);glVertex2f(x2, y2);glEnd();,OpenGL Code for Sierpinski Gasket,See p. 41 of textCode leaves many open questions by using default values colors image posit

7、ion size clipping? persistence,A Resulting Image,Coordinate System,Early systems depended on specific device mapping Device-independent graphics broke link Use application or problem coordinate system to define image Use device coordinates, raster coordinates, screen coordinates for device,Coordinat

8、es,Application coordinates can be integer or real and multi-dimensional Screen or raster coordinates are always integer and essentially 2-dimensional Graphics program maps application coordinates onto device coordinates,App to Device Mapping,Classes for OpenGL Functions,Primitives draw points, line

9、segments, polygons, text, curves, surfaces Attributes specify display characteristics of objects: color, fill, line width, font Viewing determine aspects of view: position and angle of camera, view port size, ,Function Classes (cont),Transformations change appearance or characteristics of objects: r

10、otate, scale, translate Input handle keyboard, mouse, etc. Control communicate with window system Inquiry get display information: size, raster value, ,OpenGL Interface,Graphics Utility Interface (GLU) Creates common objects like spheres GL Utility Toolkit (GLUT) Provides generic interface to window

11、 system GLX for Unix/Linux and wgl for Microsoft Windows provide low-level glue to window system,Library Organization,Using Libraries,Header files #include #include #include On some systems the GL/ is not used,Primitives,OpenGL supports both geometric primitives and raster primitives,Geometric Primi

12、tives,Points = GL_POINTS vertex displayed with size = 1 pixel Line segments = GL_LINES defined by pairs of vertices as endpoints of segments Polygons = GL_LINE_STRIPE or GL_LINE_LOOP Loop is closed, stripe is not,Primitive Examples,Properties of Polygons,Defined by line loop border Simple if no edge

13、s cross Convex if every line segment connecting pair of points on boundary or inside lies completely inside,Polygon Types in OpenGL,Polygons are either filled regions (default) or boundaries Set with glPolygonMode To get polygon with boundary must draw twice, once as filled and once as boundary or l

14、ine loop,Special Polygons,GL_TRIANGLES, GL_QUADS Groups of 3 or 4 points are grouped as triangles or quadrilaterals,Special Polygons,GL_TRIANGLE_STRIPE, GL_QUAD_STRIPE, GL_TRIANGEL_FAN Contiguous stripe or fan of triangles or quadrilaterals,Drawing a Sphere,Draw great circles Fill between latitudes

15、with quad strips Fill caps with triangle fans Code on p.52,Text,May be raster from bit map Fast Does not scale well Poor in rotation other than 90o Vector from drawn curves Slow to draw Scales, rotates, etc. well,Raster text,Color,The physiology of vision leads to 3-color theory Any color can be pro

16、duced by a combination of red, green, and blue at intensities that produce the same response in the cones as the true color,Colors in OpenGL,Colors are stored using 4 attributes, RGBA A = Alpha channel Controls opacity or transparency Color values can be integers in range from 0 to max component val

17、ue 0 255 for 24-bit color Real numbers between 0.0 and 1.0,Colors in OpenGL (cont),Colors are set with glColor* functions * is two characters, nt n = 3 or 4 color values t = date type: i, f, etc.,Clearing Frame Buffer,To get predictable results a program must first clear the frame bufferglClearColor

18、(1.0, 1.0, 1.0, 1.0) sets color to white,Indexed Color,OpenGL also supports indexed color Saves space when only a limited number of distince colors are used,Indexed Color (cont),Set color in table withglutSetColor(int color, GLfloat red,GLfloat blue, GLfloat green) Access color in table withglIndexi

19、(element),Viewing,Based on synthetic camera model If nothing is specified, there are default viewing parameters Rarely used Would force us to fit model world to camera Prefer flexibility of setting viewing parameters,Two-Dimensional Viewing,Selected rectangle from 2-dimensional world is displayed Ca

20、lled viewing rectangle or clipping rectangle,Viewing Volume,2-dimensional viewing is special case of 3-dimensional viewing viewing volume Default is 2 x 2 x 2 cube centered at (0,0,0),Orthographic Projection,Projects point (x,y,z) onto (x,y,0) View is perpendicular to plane x=0 Set viewing rectagle

21、withvoid glOrtho(GLdouble left, GLdouble right, GLdouble bottom,GLdouble top),Matrix Modes,Graphic pipelines perform matrix transformations on images at each stage Most important matrices are model-view projection State includes both,Manipulating Mode Matrices,Matrix mode operations operate on matri

22、x for currently selected mode Model-view is default Mode is set with glMatrixMode(mode) mode = GL_PROJECTION, GL_MODELVIEW, etc. Always return to model-view to insure consistency,Control Functions,Depend on particular window system GLUT provides standard set of basic operations We will consider only

23、 these,Window Control,Operations only on display window for the program Initialization glutInit Creation glutCreateWindow Display mode glutInitDisplayMode RGB or indexed hidden-surface removal singer or double buffering,Example Code,glutInit(,Aspect Ratio and Viewports,Ratio of width to length is as

24、pect ratio If aspect ratio of viewing rectangle and window differ, image will be stretched and distorted Viewport defines region of screen in which to display image Can eliminate distortion,Distortion,Viewport,Set viewport with void glViewport(GLint x, GLint y,GLsizei w, GLsizei h),GLUT Main Loop,If

25、 we simply run an OpenGL program it will display the image and exit may not allow time to see it could sleep program to keep window open but this is limited solution GLUT provides controls to avoid this Keep program running waiting for eventvoid glutMainLoop(void),Glut Display,To display an image, c

26、ode a function to create the image and have GLUT call it image drawing function takes no arguments and returns no result Any parameters must be passed through global variables void glutDisplayFunc(void (*func)(void),Simple Main Program,#include void main(int argc, char *argv) glutInit(,Simple Main P

27、rogram (cont),glutCreateWindow(“My Image“);glutDisplayFunc(display);myinit();glutMainLoop(); ,Program Structure,Key components initialization display callback function mainGasket Program codegasket.c 2-d codegasket2.c 3-d with colors /code/gasket3.c 3-d with polygons,Hidden Surface Removal,Z-buffer algorithm Z coordinate determines depth Point nearer camera obscures one with greater depth Steps Init with GLUT_DEPTH glEnable(GL_DEPTH_TEST can also disable clear before redrawing,Sample HSR Program,void display() glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT)tetrahedron(n)glFlush(); ,

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1