More Drawing Tools - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

More Drawing Tools

Description:

Ex.3.2.4b: Tiling with dino motif. setWindow(0, 640, 0, 440); for (int I=0; I 5; I ) ... drawPolylineFile('dino.dat');} Ex.3.2.6: zooming, animation, double buffering ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 13
Provided by: cis86
Category:

less

Transcript and Presenter's Notes

Title: More Drawing Tools


1
More Drawing Tools
  • (Viewports)
  • www.cis.syr.edu/mohan/gra4.ppt

2
World vs. Screen
  • Scaling and translation transformations required
    to map desired portion of world to desired
    section of screen
  • World window which part of the world is to be
    drawn, specified in world coordinates
  • Viewport rectangular section of screen window to
    which world window must be mapped

3
Window-to-viewport mapping
  • Left, top, right, bottom borders of world window
    must be mapped to corresponding screen
    coordinates
  • Proportionality forces linearity
  • sx Ax C
  • sy By D
  • where A(V.r-V.l)/(W.r-W.l), and
  • CV.l - AW.l, similarly for B,D

4
Example
  • (W.l, W.r, W.t, W.b)(0, 2, 0, 1)
  • (V.l, V.r, V.t, V.b) (40, 400, 60, 300)
  • A180, C40, B240, D60
  • sx 180x 40
  • sy 240y 60

5
OpenGL commands
  • World window set up gluOrtho2d (l, r, b, t)
    preceded by glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
  • Viewport setp glViewport(x, y, width, height)

6
Handy functions
  • void setWindow (float l, r, b, t)
  • glMatrixMode(GL_PROJECTION)
  • glLoadIdentity()
  • gluOrtho2D(l, r, b, t)
  • void setViewport(int l, r, b, t)
  • glViewport(l, b, r-l, t-b)

7
Example depicting sinc(x)
  • void myDisplay (void)
  • setWindow(-5, 5, -0.3, 1)
  • setViewport(0, 640, 0, 480)
  • glBegin(GL_LINE_STRIP)
  • for (GLfloat x-4.0 xlt4.0 x 0.1)
  • glVertex2f(x, sin(3.14 x)/(3.14 x) )
  • glEnd() glFlush()

8
Ex.3.2.4b Tiling with dino motif
  • setWindow(0, 640, 0, 440)
  • for (int I0 Ilt5 I)
  • for (int j0 jlt5 j)
  • if ((Ij)2 0)
  • setWindow(0, 640, 0, 440)
  • else setWindow(0,640, 440,0)
  • glViewport(I64, j44, 64, 44)
  • drawPolylineFile(dino.dat)

9
Ex.3.2.6 zooming, animation, double buffering
  • In main(), glutInitDisplayMode(GLUT_DOUBLEGLUT_RG
    B)
  • In myDisplay()
  • float cx0.3, cy0.2
  • float H, W 1.2, aspect 0.7
  • Set viewport
  • for (int frame0 frame lt NF frame)
  • clear screen W 0.7 H W aspect
  • setWindow(cx-W, cxW, cy-H, cyH)
  • hexSwirl() //draw object
  • glutSwapBuffers()

10
Setting window automatically
  • Compute extent of window, by finding the min. and
    max. x and y coordinates among all points.
  • If the object is procedurally defined, first
    execute the procedure without drawing, just to
    compute the extent then re-execute it to perform
    drawing.

11
Setting Viewport Automatically
  • Goal to draw largest possible undistorted
    version of figure that fits in screen window.
  • If world window aspect ratio R gtW/H,
  • setViewport(0, W, 0, W/R)
  • else setViewport(0, HR, 0, H)

12
Resizing Screen Window
  • glutReshapeFunc(myReshape) in main()
  • void myReshape( GLsizei W, GLsizei H)
  • if (RgtW/H)
  • setViewport(0, W, 0, W/R)
  • else setViewport(0, HR, 0, H)
Write a Comment
User Comments (0)
About PowerShow.com