Lecture 7. 2D Viewing • 2D viewing pipeline • Clipping window, • Normalization • viewport transformation • OpenGL 2D viewing functions • Setup clipping window, viewport •
Download ReportTranscript Lecture 7. 2D Viewing • 2D viewing pipeline • Clipping window, • Normalization • viewport transformation • OpenGL 2D viewing functions • Setup clipping window, viewport •
Lecture 7. 2D Viewing • 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 Lecture 7 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) The section of 2D scene selected for display • Display window • Viewport Lecture 7 2D viewing 2 Lecture 7 2D viewing 3 Lecture 7 2D viewing 4 Lecture 7 2D viewing 5 Lecture 7 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 S2 T3 S1 T2 R T1 M mc,wc V1 M V1 Lecture 7 2D viewing 7 OpenGL 2D viewing functions • OpenGL has no specific functions for 2D viewing. 2D viewing is a special case of 3D viewing glMatrixMode(GL-PROJECTION) • Designate the projection matrix as the current matrix. Which is originally the identity matrix. Set the current matrix as identity matrix glLoadIdentity(); • GLU clipping window function gluOrtho2D(xwmin, xwmax, ywmin, ywmax); • OpenGL viewport function glViewport(xvmin, yvmin, vpWidth, vpHeight); Lecture 7 2D viewing 8 GLUT display window functions • Set Color mode, buffer mode • glutInitDispalyMode(GLUT_SINGLE | GLUT_RGB); glClearColor(red, green, blue, alpha); 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 7 2D viewing 9 Managing multiple GLUT display windows glutIconifyWindow(); glutSetIconTitle(“Icon Name”); glutSetWindowTitle(“New window name”); glutPopWindow(); glutPushWindow(); glutHideWindow(); glutShowWindow(); glutCreateSubWindow(……) Lecture 7 2D viewing 10 Clipping algorithms • 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 clipping Line Clipping (straight-lines Segments) Area Clipping (Polygons, Curve-boundary Areas) Curve Clipping Text Clipping Lecture 7 2D viewing 11 Point clipping • 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 window position in WC or SC. Lecture 7 2D viewing 12 Line Clipping • Possible relationships between line positions and a clipping rectangle: 1. 2. 3. 4. Totally out Totally in in-and-out out-in-out Lecture 7 2D viewing 13 Lecture 7 2D viewing 14 Lecture 7 2D viewing 15 Lecture 7 2D viewing 16 Lecture 7 2D viewing 17 Lecture 7 2D viewing 18 Lecture 7 2D viewing 19 Lecture 7 2D viewing 20 Lecture 7 2D viewing 21 Lecture 7 2D viewing 22 Lecture 7 2D viewing 23 Lecture 7 2D viewing 24 Lecture 7 2D viewing 25 Lecture 7 2D viewing 26 Lecture 7 2D viewing 27 Lecture 7 2D viewing 28 Lecture 7 2D viewing 29 Lecture 7 2D viewing 30 Lecture 7 2D viewing 31 Lecture 7 2D viewing 32