Lecture 7 2D viewing 1 Lecture 7. 2D Viewing 2D viewing pipeline Clipping window, Normalization...

Preview:

Citation preview

Lecture 7 2D viewing 1

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 2

2D viewing pipeline• Transformation vertices from MC to DC in five stages

Construct WC scene using MC transformation

Convert WC to VC

Transform VC to NC

Map NC to DC

MC WC VC NC DC

• Clipping window (world window, or viewing window)The section of 2D scene selected for display

• Display window

• Viewport

Lecture 7 2D viewing 3

Lecture 7 2D viewing 4

Lecture 7 2D viewing 5

Lecture 7 2D viewing 6

Lecture 7 2D viewing 7

2D viewing pipeline transformations

Construct WC scene using MC transformation

Convert WC to VC

Transform VC to NC

Map NC to DC

MC WC VC NC DC

MC

VC

NC

DCMC

WC

WC

VC

,mc wcM

,'mc wcM

1R T

1 2S T

2 3S T

2 3 1 2 1 , 1 1mc wcV S T S T R T M V M V

1V V

Lecture 7 2D viewing 8

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 functiongluOrtho2D(xwmin, xwmax, ywmin, ywmax);

• OpenGL viewport functionglViewport(xvmin, yvmin, vpWidth, vpHeight);

Lecture 7 2D viewing 9

GLUT display window functions• Set Color mode, buffer mode

glutInitDispalyMode(GLUT_SINGLE | GLUT_RGB);glClearColor(red, green, blue, alpha);glClearIndex(index);

• Display-window identifierglutSetWindow(windowID);currentWindowID = glutGetWindow();

• Deleting a GLUT display window

glutDestroyWindow(windowID);• Relocate and resize

glutPositionWindow(x, y);glutReshapeWindow(newWidth, newHeight);

• Display window relocate, and resizeglutFullScreen();glutReshapeFunc(winreshapFcn);

Lecture 7 2D viewing 10

Managing multiple GLUT display windows

glutIconifyWindow();glutSetIconTitle(“Icon Name”);glutSetWindowTitle(“New window name”); glutPopWindow();glutPushWindow();glutHideWindow();glutShowWindow();

glutCreateSubWindow(……)

Lecture 7 2D viewing 11

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 12

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 13

Line Clipping• Possible relationships between line positions and a clipping

rectangle:1. Totally out

2. Totally in

3. in-and-out

4. out-in-out

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

Recommended