1 / 19

CS430 Computer Graphics

CS430 Computer Graphics. Rendering Pipeline and Primitive Rasterization. Topics. Introduction Viewport Transformation Primitive Rasterization Primitive Clipping. Introduction. Scan conversion Convert specification of a primitive into pixels in the frame buffer Simple rendering pipeline.

chinara
Download Presentation

CS430 Computer Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Topics • Introduction • Viewport Transformation • Primitive Rasterization • Primitive Clipping

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

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

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

  6. World Window and Viewport • Example

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

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

  9. Window-to-Viewport Mapping

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

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

  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. 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. Zooming and Panning • Zooming • Scale the world window with respect to the center of the world window with viewport fixed • Panning • Shift the world window with viewport fixed

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

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

  17. Resize Screen Window • glutReshapeFunc(myReshape) • Prototype of myReshape • void myReshape(GLsizei W, Glsizei H); • W and H: new width and height • Making a matched viewport • void 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. Primitives Rasterization • Line • Brute force • DDA • Midpoint algorithm • Circle • Brute force • Polar coordinates • Midpoint algorithm • Polyline and polygon

  19. Primitive Clipping • Problem • Not everything defined in the world will be included in the world window • Solution • Clipping • Line clipping • Polygon clipping • OpenGL does clipping for you

More Related