SlideShare a Scribd company logo
11
Most read
12
Most read
13
Most read
2D Drawing
Filling Rectangle, Filling Polygon
Coordinate Systems

We have been using the coordinate system of the
 screen window (in pixels).
The range is from 0 (left) to some value screenWidth
 – 1 in x, and from 0 (usually top) to some value
 screenHeight –1 in y.
    We can use only positive values of x and y.
    The values must have a large range (several hundred pixels) to
     get a reasonable size drawing.
CONTINUE…

It may be much more natural to think in terms of x
 varying from, say, -1 to 1, and y varying from –100.0
 to 20.0.
We want to separate the coordinates we use in a
 program to describe the geometrical object from the
 coordinates we use to size and position the pictures
 of the objects on the display.
Description is usually referred to as a modeling
 task, and displaying pictures as a viewing task.
WORLD COORDINATES

The space in which objects are described is called
 world coordinates (the numbers used for x and y
 are those in the world, where the objects are
 defined).
World coordinates use the Cartesian xy-coordinate
 system used in mathematics, based on whatever
 units are convenient.
world window

We define a rectangular world window in these
 world coordinates.
The world window specifies which part of the world
 should be drawn: whichever part lies inside the
 window should be drawn, and whichever part lies
 outside should be clipped away and not drawn.
OpenGL     does      the   clipping   automatically.
viewport

In addition, we define a rectangular viewport in the
 screen window on the display.
A mapping (consisting of scalings [change size] and
 translations [move object]) between the world
 window and the viewport is established by OpenGL.
The  objects inside the world window appear
 automatically at proper sizes and locations inside the
 viewport (in screen coordinates, which are pixel
 coordinates on the display).
Coordinate Systems Example

 We   want to graph



 Sinc(0)= 1 by
 definition.
 Interesting parts of
 the function are in
 -4.0 ≤ x ≤ 4.0.
Set WW

 The function setWindow sets the world window size:



void setWindow(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top)
{
       glMatrixMode(GL_PROJECTION);

      glLoadIdentity();

      gluOrtho2D(left, right, bottom, top);

}
Set VP

void setViewport(GLint left, GLint right, GLint bottom, GLint top)
{
    glViewport(left, bottom, right - left, top - bottom);
}




 Calls: setWindow(-5.0, 5.0, -0.3, 1.0);
         setViewport(0, 640, 0, 480);

In myInit();
Windows and Viewports

We use natural coordinates for what we are drawing
 (the world window).
OpenGL    converts our coordinates to screen
 coordinates when we set up a screen window and a
 viewport. The viewport may be smaller than the
 screen window. The default viewport is the entire
 screen window.
The   conversion requires scaling and shifting:
 mapping the world window to the screen window
 and the viewport.
Windows and Viewport
Mapping From the Window to VIEWPORT

Windows are described by their left, top, right, and
 bottom values, w.l, w.t, w.r, w.b.
Viewports are described by the same values: v.l, v.t,
 v.r, v.b, but in screen window coordinates.
Window-to-Viewport Mapping (Transformation)


We want our mapping to be proportional: for
 example, if x is ¼ of the way between the left and
 right world window boundaries, then the screen x (sx)
 should be ¼ of the way between the left and right
 viewport boundaries.
CONTINUE….

Proportionality forces the mappings to have a linear
 form:
     sx= A * x + C,
     sy = B * y + D
 For some constants A, B, C and D. The constants A and B scale the x
 and y coordinates, and C and D shift (or translate) them.

 How can A, B, C, and D be determined?
 Consider first the mapping for x.


 After algebraic manipulation


         Or
              A = (V.r-V.l)/(W.r-W.l),
              C = V.l – A*w.l
CONTINUE…

Similarly, proportionality in y dictates that




  and writing sy as B y + D yields:
CONTINUE…
Example

Consider the window and viewport of Figure The
 window has (W.l, W.r, W.b, W.t) = (0, 2.0, 0, 1.0)
 and the viewport has (V.l, V.r, V.b, V.t) = (40, 400,
 60, 300).
Solution:

 Using the above eq:



Thus for this example, the window to viewport
  mapping is:

Check that this mapping properly maps various
 points of interest, such as
Each corner of the window is indeed mapped to the
 corresponding corner of the viewport. For example,
 (2.0, 1.0) maps to (400, 300).
CONTINUE….

The center of the window (1.0, 0.5) maps to the
 center of the viewport (220, 180 )
Practice Exercise

Find values of A, B, C, and D for the case of a world
 window (10.0, 10.0, -6.0, 6.0) and a viewport (0,
 600, 0, 400).
oGL Functions To Create the Map

Because OpenGL uses matrices to set up all its
 transformations, the call to gluOrtho2D() must be
 preceded by two setup functions:

   glMatrixMode(GL_PROJECTION);
   glLoadIdentity(); //to reset the matrix
Application:Tiling with Viewports

More Related Content

PPT
Window to viewport transformation
Ankit Garg
 
PPTX
Window to viewport transformation&matrix representation of homogeneous co...
Mani Kanth
 
PPTX
Bresenham's line algorithm
Pooja Dixit
 
PDF
2D Transformation in Computer Graphics
A. S. M. Shafi
 
PPTX
Bresenham circle
Taher Barodawala
 
PPT
Visible surface detection in computer graphic
anku2266
 
PPT
Line drawing algo.
Mohd Arif
 
Window to viewport transformation
Ankit Garg
 
Window to viewport transformation&matrix representation of homogeneous co...
Mani Kanth
 
Bresenham's line algorithm
Pooja Dixit
 
2D Transformation in Computer Graphics
A. S. M. Shafi
 
Bresenham circle
Taher Barodawala
 
Visible surface detection in computer graphic
anku2266
 
Line drawing algo.
Mohd Arif
 

What's hot (20)

PPT
2D transformation (Computer Graphics)
Timbal Mayank
 
PPTX
Computer graphics LINE DRAWING algorithm.pptx
R S Anu Prabha
 
PPTX
Window to Viewport Transformation in Computer Graphics with.pptx
Dolchandra
 
PDF
Unit 3
ypnrao
 
PPT
2d transformation
Sarkunavathi Aribal
 
PPT
Composite transformations
Mohd Arif
 
PPTX
Halftoning in Computer Graphics
University of Potsdam
 
PPTX
Graphics_3D viewing
Rabin BK
 
PPTX
3d transformation computer graphics
University of Potsdam
 
PPTX
Character generation techniques
Mani Kanth
 
PPTX
Composite transformation
Pooja Dixit
 
PPT
fractals
Yogesh jatin Gupta
 
PPTX
Computer graphics basic transformation
Selvakumar Gna
 
PDF
3D Transformation
SwatiHans10
 
PPT
Intro to scan conversion
Mohd Arif
 
PPTX
Concept of basic illumination model
Ankit Garg
 
PPTX
2 d viewing computer graphics
KALESHWAR KUMAR
 
PPTX
The sutherland hodgeman polygon clipping algorithm
Mani Kanth
 
PPT
computer graphics
Megabi Mamo
 
2D transformation (Computer Graphics)
Timbal Mayank
 
Computer graphics LINE DRAWING algorithm.pptx
R S Anu Prabha
 
Window to Viewport Transformation in Computer Graphics with.pptx
Dolchandra
 
Unit 3
ypnrao
 
2d transformation
Sarkunavathi Aribal
 
Composite transformations
Mohd Arif
 
Halftoning in Computer Graphics
University of Potsdam
 
Graphics_3D viewing
Rabin BK
 
3d transformation computer graphics
University of Potsdam
 
Character generation techniques
Mani Kanth
 
Composite transformation
Pooja Dixit
 
Computer graphics basic transformation
Selvakumar Gna
 
3D Transformation
SwatiHans10
 
Intro to scan conversion
Mohd Arif
 
Concept of basic illumination model
Ankit Garg
 
2 d viewing computer graphics
KALESHWAR KUMAR
 
The sutherland hodgeman polygon clipping algorithm
Mani Kanth
 
computer graphics
Megabi Mamo
 
Ad

Viewers also liked (12)

PDF
Hermite bicubic-surface-patch
Rohit Gothwal
 
PPTX
Surface representation
Sunith Guraddi
 
PPTX
Windows to viewport transformation
Prashant Singh
 
PDF
Coons bicubic surface
ramac123
 
PDF
Curves And Surfaces Representation And Application
Diaa ElKott
 
PDF
B spline
aa11bb11
 
PPTX
Group Technology
Sunith Guraddi
 
PDF
Curves and surfaces
Mohammed Mahmoud
 
PPTX
Cellular manufacturing and group technology
Hitendrasinh Zala
 
PPTX
FLEXIBLE MANUFACTURING SYSTEM
Anand Khare
 
PPT
Concurrent Engineering
Nitin Chandekar
 
PPT
Concurrent Engineering
ajithsrc
 
Hermite bicubic-surface-patch
Rohit Gothwal
 
Surface representation
Sunith Guraddi
 
Windows to viewport transformation
Prashant Singh
 
Coons bicubic surface
ramac123
 
Curves And Surfaces Representation And Application
Diaa ElKott
 
B spline
aa11bb11
 
Group Technology
Sunith Guraddi
 
Curves and surfaces
Mohammed Mahmoud
 
Cellular manufacturing and group technology
Hitendrasinh Zala
 
FLEXIBLE MANUFACTURING SYSTEM
Anand Khare
 
Concurrent Engineering
Nitin Chandekar
 
Concurrent Engineering
ajithsrc
 
Ad

Similar to Windows and viewport (20)

PPTX
chapter 3.pptxGeometry chapter 4 and 5 transformation ,translation ,animation...
Antenehsolomon2
 
PDF
201707 SER332 Lecture 07
Javier Gonzalez-Sanchez
 
PPTX
3 d graphics with opengl part 2
Sardar Alam
 
PDF
CG3_ch3+ch4computergraphicsbreesenhan.pdf
VikramBhathal
 
DOCX
computer graphics slides by Talha shah
Syed Talha
 
PPT
Two dimensional viewing
Mohd Arif
 
PPT
Computer Graphics involves technology to access. The Process transforms and p...
ErNandiniDharne
 
PPT
Opengl (1)
ch samaram
 
PPT
september11.ppt
CharlesMatu2
 
PPT
Csc406 lecture7 device independence and normalization in Computer graphics(Co...
Daroko blog(www.professionalbloggertricks.com)
 
PPT
Drawing Tools
Ghaffar Khan
 
PDF
Open gl basics
saad siddiqui
 
PPTX
CGChapter 3.pptx
YazanAlbilleh
 
PDF
OpenGL L02-Transformations
Mohammad Shaker
 
PPT
Lec4
Sahil Dahiya
 
PPTX
Clipping CG ppt.pptx
AamirSheikh49
 
PPTX
3 CG_U1_P2_PPT_3 OpenGL.pptx
ssuser255bf1
 
PPTX
OpenGL Introduction
Jayant Mukherjee
 
PPT
Programming with OpenGL
Syed Zaid Irshad
 
chapter 3.pptxGeometry chapter 4 and 5 transformation ,translation ,animation...
Antenehsolomon2
 
201707 SER332 Lecture 07
Javier Gonzalez-Sanchez
 
3 d graphics with opengl part 2
Sardar Alam
 
CG3_ch3+ch4computergraphicsbreesenhan.pdf
VikramBhathal
 
computer graphics slides by Talha shah
Syed Talha
 
Two dimensional viewing
Mohd Arif
 
Computer Graphics involves technology to access. The Process transforms and p...
ErNandiniDharne
 
Opengl (1)
ch samaram
 
september11.ppt
CharlesMatu2
 
Csc406 lecture7 device independence and normalization in Computer graphics(Co...
Daroko blog(www.professionalbloggertricks.com)
 
Drawing Tools
Ghaffar Khan
 
Open gl basics
saad siddiqui
 
CGChapter 3.pptx
YazanAlbilleh
 
OpenGL L02-Transformations
Mohammad Shaker
 
Clipping CG ppt.pptx
AamirSheikh49
 
3 CG_U1_P2_PPT_3 OpenGL.pptx
ssuser255bf1
 
OpenGL Introduction
Jayant Mukherjee
 
Programming with OpenGL
Syed Zaid Irshad
 

Windows and viewport

  • 2. Coordinate Systems We have been using the coordinate system of the screen window (in pixels). The range is from 0 (left) to some value screenWidth – 1 in x, and from 0 (usually top) to some value screenHeight –1 in y.  We can use only positive values of x and y.  The values must have a large range (several hundred pixels) to get a reasonable size drawing.
  • 3. CONTINUE… It may be much more natural to think in terms of x varying from, say, -1 to 1, and y varying from –100.0 to 20.0. We want to separate the coordinates we use in a program to describe the geometrical object from the coordinates we use to size and position the pictures of the objects on the display. Description is usually referred to as a modeling task, and displaying pictures as a viewing task.
  • 4. WORLD COORDINATES The space in which objects are described is called world coordinates (the numbers used for x and y are those in the world, where the objects are defined). World coordinates use the Cartesian xy-coordinate system used in mathematics, based on whatever units are convenient.
  • 5. world window We define a rectangular world window in these world coordinates. The world window specifies which part of the world should be drawn: whichever part lies inside the window should be drawn, and whichever part lies outside should be clipped away and not drawn. OpenGL does the clipping automatically.
  • 6. viewport In addition, we define a rectangular viewport in the screen window on the display. A mapping (consisting of scalings [change size] and translations [move object]) between the world window and the viewport is established by OpenGL. The objects inside the world window appear automatically at proper sizes and locations inside the viewport (in screen coordinates, which are pixel coordinates on the display).
  • 7. Coordinate Systems Example  We want to graph  Sinc(0)= 1 by definition. Interesting parts of the function are in -4.0 ≤ x ≤ 4.0.
  • 8. Set WW  The function setWindow sets the world window size: void setWindow(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(left, right, bottom, top); }
  • 9. Set VP void setViewport(GLint left, GLint right, GLint bottom, GLint top) { glViewport(left, bottom, right - left, top - bottom); }  Calls: setWindow(-5.0, 5.0, -0.3, 1.0);  setViewport(0, 640, 0, 480); In myInit();
  • 10. Windows and Viewports We use natural coordinates for what we are drawing (the world window). OpenGL converts our coordinates to screen coordinates when we set up a screen window and a viewport. The viewport may be smaller than the screen window. The default viewport is the entire screen window. The conversion requires scaling and shifting: mapping the world window to the screen window and the viewport.
  • 12. Mapping From the Window to VIEWPORT Windows are described by their left, top, right, and bottom values, w.l, w.t, w.r, w.b. Viewports are described by the same values: v.l, v.t, v.r, v.b, but in screen window coordinates.
  • 13. Window-to-Viewport Mapping (Transformation) We want our mapping to be proportional: for example, if x is ¼ of the way between the left and right world window boundaries, then the screen x (sx) should be ¼ of the way between the left and right viewport boundaries.
  • 14. CONTINUE…. Proportionality forces the mappings to have a linear form: sx= A * x + C, sy = B * y + D For some constants A, B, C and D. The constants A and B scale the x and y coordinates, and C and D shift (or translate) them. How can A, B, C, and D be determined? Consider first the mapping for x. After algebraic manipulation Or A = (V.r-V.l)/(W.r-W.l), C = V.l – A*w.l
  • 15. CONTINUE… Similarly, proportionality in y dictates that and writing sy as B y + D yields:
  • 17. Example Consider the window and viewport of Figure The window has (W.l, W.r, W.b, W.t) = (0, 2.0, 0, 1.0) and the viewport has (V.l, V.r, V.b, V.t) = (40, 400, 60, 300).
  • 18. Solution:  Using the above eq: Thus for this example, the window to viewport mapping is: Check that this mapping properly maps various points of interest, such as Each corner of the window is indeed mapped to the corresponding corner of the viewport. For example, (2.0, 1.0) maps to (400, 300).
  • 19. CONTINUE…. The center of the window (1.0, 0.5) maps to the center of the viewport (220, 180 )
  • 20. Practice Exercise Find values of A, B, C, and D for the case of a world window (10.0, 10.0, -6.0, 6.0) and a viewport (0, 600, 0, 400).
  • 21. oGL Functions To Create the Map Because OpenGL uses matrices to set up all its transformations, the call to gluOrtho2D() must be preceded by two setup functions: glMatrixMode(GL_PROJECTION); glLoadIdentity(); //to reset the matrix