Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chi-Cheng Lin, Winona State University CS430 Computer Graphics Rendering Pipeline and Primitive Rasterization.

Similar presentations


Presentation on theme: "Chi-Cheng Lin, Winona State University CS430 Computer Graphics Rendering Pipeline and Primitive Rasterization."— Presentation transcript:

1 Chi-Cheng Lin, Winona State University CS430 Computer Graphics Rendering Pipeline and Primitive Rasterization

2 2 Topics l Introduction l Viewport Transformation l Primitive Rasterization l Primitive Clipping

3 3 Introduction l Scan conversion zConvert specification of a primitive into pixels in the frame buffer l Simple rendering pipeline Model Viewport Transformation Scan Conversion Pixels on display

4 4 Viewport Transformation l Problem zWhen we define a 2D model, we want to use whatever coordinate values and units convenient to use in the 2D Cartesian system. zBUT, the coordinate values on the display (or in the screen window) are always nonnegative measured in pixels. zALSO, we might want to show different parts of our model in different places on the display (or in the screen window) l Solution: viewport transformation

5 5 World Window and Viewport l World coordinate zSpace in which objects are described l World window zA rectangle area specifies which part of the “world” should be drawn l Viewport zA rectangle area specifies which part on the display (or in the window) the world window is mapped to

6 6 World Window and Viewport l Example

7 7 Window-to-Viewport Mapping l (x, y) in world window should be mapped to (sx, sy) in viewport proportionally  distortion is possible

8 8 Window-to-Viewport Mapping (x,y)(x,y) (sx,sy) x - W.l y - W.b sy - V.b sx - V.l l Every vertex used in window to define an object should be mapped to viewport

9 9 Window-to-Viewport Mapping

10 10 How does OpenGL do it? l Set up world window zglMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(left, right, bottom, top); zWe can write a function setWindow() ysetWindow(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(left, right, bottom, top); }

11 11 How does OpenGL do it? l Set up viewport zglViewport(left, bottom, width, height); or glViewport(left, bottom, right-left, top-bottom); zDefault viewport = screen window size l Parameters to set up a window are doubles while those to set up a viewport are ints. (Why?)

12 12 Example: Tiling with Motif setWindow(0,640.0,0,440.0); // set a fixed window for (int i=0; i<5; i++) // for each column for (int j=0; j<5; j++) { // for each row glViewport(i*64, j*44, 64, 44); // set the next viewport drawPolylineFile(“dino.dat ”); // draw it again }

13 13 Example: Tiling with Motif for (int i = 0; i < 5; i++) for (int j = 0; j < 5; j++) { if ((i+j)%2 = 1) // if (i+j) is odd setWindow(0.0, 640.0, 0.0, 440.0); // right-side-up window else setWindow(0.0, 640.0, 440.0, 0.0); // upside-down window glViewport(i*64, j*44, 64, 44); // set the next viewport drawPolylineFile("dino.dat"); // draw it again }

14 14 Zooming and Panning l Zooming zScale the world window with respect to the center of the world window with viewport fixed l Panning zShift the world window with viewport fixed

15 15 Mapping without Distortion l To prevent from distortion, a viewport with the same aspect ratio of world window is required. zAspect ratio: width/height l How do you draw the largest undistorted picture in the screen window?

16 16 Mapping without Distortion l If aspect ratio of world window = R zTwo cases glViewport(0,0,W,W/R); glViewport(0,0,H*R,H);

17 17 Resize Screen Window l glutReshapeFunc(myReshape) l Prototype of myReshape zvoid myReshape(GLsizei W, Glsizei H); zW and H: new width and height l Making a matched viewport zvoid myReshape(GLsizei W,GLsizei H) { if (R >W/H) //use (global)window aspect ratio setViewport(0, W, 0, W/R); else setViewport(0, H*R, 0, H); }

18 18 Primitives Rasterization l Line zBrute force zDDA zMidpoint algorithm l Circle zBrute force zPolar coordinates zMidpoint algorithm l Polyline and polygon

19 19 Primitive Clipping l Problem zNot everything defined in the world will be included in the world window l Solution zClipping l Line clipping l Polygon clipping l OpenGL does clipping for you


Download ppt "Chi-Cheng Lin, Winona State University CS430 Computer Graphics Rendering Pipeline and Primitive Rasterization."

Similar presentations


Ads by Google