CS430 Computer Graphics - PowerPoint PPT Presentation

About This Presentation
Title:

CS430 Computer Graphics

Description:

gluOrtho2D(left, right, bottom, top); We can write a function setWindow() setWindow(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top) ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 20
Provided by: ChiChe7
Learn more at: https://cs.winona.edu
Category:

less

Transcript and Presenter's Notes

Title: CS430 Computer Graphics


1
CS430 Computer Graphics
  • Rendering Pipeline and Primitive Rasterization

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 i0 ilt5 i) // for each column
  • for (int j0 jlt5 j) // for each row
  • glViewport(i64, j44, 64, 44) // set the next
    viewport
  • drawPolylineFile(dino.dat ) // draw it again

13
Example Tiling with Motif
  • for (int i 0 i lt 5 i)
  • for (int j 0 j lt 5 j)
  • if ((ij)2 1) // if (ij) 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(i64, j44, 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,HR,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 gtW/H) //use (global)window aspect ratio
  • setViewport(0, W, 0, W/R)
  • else
  • setViewport(0, HR, 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
Write a Comment
User Comments (0)
About PowerShow.com