Lecture 13. 2D Viewing g • 2D viewing pipeline • Clipping window, • Normalization • viewport transformation • OpenGL 2D viewing functions • Setup clipping window, viewport • Display window managing • Clipping algorithms – TWO-DIMENSIONAL POINT CLIPPING – LINE CLIPPING (1) Cohen-Sutherland Line Clipping (2) Liang-Barsky Line Clipping ((3)) Nicholl-Lee-Nicholl Line Cliping p g Lecture 13 2D viewing 1 2D viewing pipeline • Transformation vertices from MC to DC in five stages MC Construct WC scene using MC transformation WC Convert WC to VC VC Transform VC to NC NC DC Map NC to DC • Clipping window (world window, or viewing window) Th section The ti off 2D scene selected l t d ffor di display l • Display window • Viewport Lecture 13 2D viewing 2 Lecture 13 2D viewing 3 Lecture 13 2D viewing 4 Lecture 13 2D viewing 5 Lecture 13 2D viewing 6 2D viewing pipeline transformations MC Construct WC scene using MC transformation MC M mc ,wc WC Convert WC to VC VC Transform VC to NC NC S2 ⋅ T3 V1 DC Map NC to DC V R ⋅ T1 WC MC S1 ⋅ T2 WC M 'mc ,wc V = S 2 ⋅ T3 ⋅ S1 ⋅ T2 ⋅ R ⋅ T1 ⋅ M mc , wc ⋅ V1 = M ⋅ V1 Lecture 13 2D viewing 7 OpenGL p 2D viewing g functions • OpenGL has no specific functions for 2D viewing. 2D viewing g is a special p case of 3D viewing g glMatrixMode(GL-PROJECTION) • Designate the projection matrix as the current matrix. Which is originally the identity matrix matrix. Set the current matrix as identity matrix glLoadIdentity(); • GLU clipping window function gluOrtho2D(xwmin, wmax, ywmin, ywmax); • OpenGL viewport function glViewport(xvmin, yvmin, vpWidth, vpHeight); Lecture 13 2D viewing 8 GLUT display p y window functions • Set Color mode, buffer mode • glutInitDispalyMode(GLUT_SINGLE | GLUT_RGB); glClearColor(red, lCl C l ( d green, bl blue, alpha); l h ) glClearIndex(index); Display-window identifier glutSetWindow(windowID); • currentWindowID = glutGetWindow(); Deleting a GLUT display window • glutDestroyWindow(windowID); Relocate and resize glutPositionWindow(x, y); glutReshapeWindow(newWidth, newHeight); • Display window relocate, and resize glutFullScreen(); glutReshapeFunc(winreshapFcn); Lecture 13 2D viewing 9 Managing g g multiple p GLUT display p y windows glutIconifyWindow(); glutSetIconTitle(“Icon glutSetIconTitle( Icon Name Name”); ); glutSetWindowTitle(“New window name”); g glutPopWindow(); p (); glutPushWindow(); glutHideWindow(); glutShowWindow(); glutCreateSubWindow(……) See program example in page 313 Lecture 13 2D viewing 10 Clipping pp g algorithms g • Clipping: Generally, any procedure that identifies those portions of a picture that are either inside or outside of a specified region of space is referred as a clipping algorithm, or simply clipping. • Types of Clipping: – – – – – Point o t clipping c pp g Line Clipping (straight-lines Segments) Area Clipping (Polygons, Curve-boundary Areas) Curve Clipping Text Clipping Lecture 13 2D viewing 11 Point clipping pp g • Given a point P=(x, y), we display the point if the following inequalities are satisfied: xwmin <= x <= xwmax ywmin <= y <= ywmax where (xwmin, xwmax , ywmin , ywmax ) defines the clipping pp g window p position in WC or SC. Lecture 13 2D viewing 12 Line Clipping pp g • Possible relationships between line positions and a clipping rectangle: 1. 2. 3. 4. Totally out Totally in in-and-out out-in-out Lecture 13 2D viewing 13 Lecture 13 2D viewing 14 Lecture 13 2D viewing 15 Lecture 13 2D viewing 16 Lecture 13 2D viewing 17 Lecture 13 2D viewing 18 Lecture 13 2D viewing 19 Lecture 13 2D viewing 20 Lecture 13 2D viewing 21 Lecture 13 2D viewing 22 Lecture 13 2D viewing 23 Lecture 13 2D viewing 24 Lecture 13 2D viewing 25 Lecture 13 2D viewing 26 Lecture 13 2D viewing 27 Lecture 13 2D viewing 28 Lecture 13 2D viewing 29 Lecture 13 2D viewing 30 Lecture 13 2D viewing 31 Lecture 13 2D viewing 32
© Copyright 2024 ExpyDoc