Computer Graphics (CoSc3121)
COMPUTER SCIENCE DEPARTMENT
DEBARK UNIVERSITY
CHAPTER FOUR- WINDOW-TO-VIEWPORTS AND
VIEWING PIPELINE
Contents
2
Window- To-Viewport
Viewing Pipeline
o Modelling Transformation
o Viewing Transformation
o Projection Transformation
o Normalization and Clipping
o Viewport Transformation
o OpenGL Viewing Pipeline
– Modelview matrix
– Projection matrix
– Viewport matrix
Computer Graphics: Chapter Four
3
• Transforms primitives from world coordinates
Window-to- to viewport coordinates.
viewport
Tansformationr
• All primitives that lie outside the world window
must be clipped.
• Primitives are displayed in a viewport of the
screen window.
• This transformation consists of a number of
parts: the viewing pipeline.
Computer Graphics: Chapter Four
4
Viewing Papeline • A sequence of transformations that
every primitive must undergo in
Modelling
Transformation order to be displayed.
Viewing
Transformation • Consists of the different
transformations:
Projection
Transformation
Normalization and
Clipping
ViewPort
Transformation
OpenGL Viewing
Pipline
Modeling Transformation
5
Modeling coordinate System: primitive coordinate
Modelling
Modeling: creating 3D scenes from basic primitives
Transformation
Modeling Transformation: transform primitives so
Viewing that they create the 3D scene we want.
Transformation World coordinate system: the resulted coordinate
system
Projection A wheel primitive being transformed in four different ways to form
Transformation the wheels of a car.
Normalization and
Clipping
ViewPort
Transformation
OpenGL Viewing
Pipline Modelling Transformation World Coordinate System
The Viewing Transformation
6
Modelling Viewing transformation: describes the position,
Transformation direction and orientation of the virtual camera.
Viewing coordinate system: the resulted coordinate
Viewing
system. Origin: the position of the camera, Z is along the
Transformation
look vector and Y is up vector.
Projection
Transformation
Normalization and
Clipping
ViewPort
Transformation
OpenGL Viewing
Pipline Viewing Coordinate System
Projection Transformation
7
Modelling Projection Transformation: taking a picture of 3D
Transformation scene and converting it in to 2D image.
To do this, we need to know about the type of camera we
Viewing
have:
Transformation
Handle the wide-angle or zooming property of the
Projection camera.
Transformation Two Types:
Parallel
Normalization and Perspective
Clipping
ViewPort
Transformation
OpenGL Viewing
Pipline
Projection Transformation
8
Modelling Parallel Projection: the projection lines are parallel to
Transformation each other. They will never meet.
Two Types:
Viewing
Transformation Orthographic : projection line intersect image plane
at right angle. They are orthogonal.
Projection Oblique: projection line intersect image plane at some
Transformation other angle. They are oblique.
orthogonal projection Oblique projection
Normalization and
Clipping
ViewPort
Transformation Image Image plane
plane
OpenGL Viewing Projection lines are parallel Projection lines parallel
Pipline and perpendicular to image but not perpendicular
plane
Projection Transformation
9
Modelling Perspective Projection: the projection lines converges
Transformation to a point (The center of Projection)
Objects which are further away from the virtual camera
Viewing
appear smaller on the image plane.
Transformation
Projection
Transformation
Normalization and
Clipping
Centre of projection Image plane
ViewPort
Transformation
OpenGL Viewing
Pipline
Normalization and Clipping
10
Clipping: the process of checking and deciding which
Modelling
Transformation primitives are visible by the camera and which ones are
not.
Viewing
Transformation
Clipping is performed by:
Projection Defining number of clipping planes
Transformation 6 clipping planes: left, right, bottom and top boarder
of the image plane and near and far planes.
Normalization and
Clipping
View Volume: bounded volume formed by the six
ViewPort clipping planes. primitives inside are visible and the rest
Transformation are not.
OpenGL Viewing
Pipline
Normalization and Clipping…
11
Modelling
Transformation
Viewing
Transformation
Projection
Transformation
Normalization and
Clipping
Near and Far Clipping Planes
ViewPort
Transformation
Volume of space between near and far clipping
planes defines what the camera can ‘see’.
OpenGL Viewing
Pipline
Modelling
Transformation
Viewing
Transformation
Projection
Transformation
Normalization and
Clipping
ViewPort
Transformation
OpenGL Viewing
Pipline
13
Modelling
Transformation
Viewing
Transformation
Projection
Transformation
Normalization and
Clipping
ViewPort
Transformation
OpenGL Viewing
Pipline
Normalization and Clipping…
14
Modelling Clipping is more efficient if it takes place in a
Transformation normalised coordinate system.
Viewing Normalising means scaling all coordinates so that
Transformation they range between 0 and 1 (or occasionally -1 and
+1).
Projection
Transformation
Once the view volume has been normalised, and
Normalization and clipping has taken place, our remaining points are in
Clipping normalised coordinates.
ViewPort
Transformation All that is left now is to draw our picture into the
display window.
OpenGL Viewing
Pipline
Viewport Transformation
15
Modelling Specifying which display area we want to use, rather than
Transformation using the whole display window.
Viewing Viewport Transformation: mapping of our coordinate
Transformation system on to the viewport in the display window.
Finally, the rendered image is in a device coordinate
Projection
system.
Transformation
Normalization and
Clipping
ViewPort
Transformation
OpenGL Viewing
Pipline
OpenGL viewing pipeline
16
Modelling OpenGL Graphics Package has 3 matrices in its
Transformation viewing pipeline
Viewing Model View matrix
Transformation Projection matrix
Viewport matrix
Projection
OpenGL has one matrix stack for each matrix in the
Transformation
viewing pipeline.
Normalization and Before applying changes to the current matrix first we
Clipping should choose which matrix stack that we are going
to use.
ViewPort
glMatrixMode(GL_MODELVIEW);
Transformation
glMatrixMode(GL_PROJECTION);
OpenGL Viewing GlViewport();
Pipline
OpenGL viewing pipeline
17
Modelling OpenGL Graphics Package has 3 matrices in its
Transformation viewing pipeline
Viewing Model View: glMatrixMode(GL_MODELVIEW);
Transformation – Combines effect of modelling transformations
and viewpoint.
Projection
Transformation
• Modelling Transformations:
Normalization and – What transformations are applied to each
Clipping primitive to construct the scene?
• Viewing Transformations:
ViewPort – Where are we viewing the scene from?
Transformation
OpenGL Viewing
Pipline
OpenGL viewing pipeline
18
Modelling • Then we can use for modeling part
Transformation GlTranslate*, glRotate*, glScale*,
glLoadMatrix*, glMultMatrix*,
Viewing
Transformation Viewing part is defined by
gluLookAt(x0, y0, z0, xref, yref, zref, Vx, Vy, Vz)
Projection
Specifies the position/direction/orientation of the
Transformation
‘camera’
Normalization and The default values are
Clipping Camera Position: (x0, y0, z0) = (0,0,0)
Camera look vector: (xref, yref, zref) = (0,0,-1)
ViewPort Camera up vector: (Vx, Vy, Vz) = (0,1,0)
Transformation
OpenGL Viewing The viewing Transformation is the same for all
Pipline primitives. How can we reuse it for all
primitives?
OpenGL viewing pipeline
19
Modelling
Transformation • For example, the following 3 lines define a virtual camera
positioned at (8, 0, 8) in world coordinates, looking at the origin,
Viewing and with the y-axis as ‘up’.
Transformation
Projection glMatrixMode(GL_MODELVIEW);
Transformation glLoadIdentity();
gluLookAt(8,0,8,0,0,0,0,1,0);
Normalization and
Clipping
ViewPort
Transformation
OpenGL Viewing
Pipline
OpenGL viewing pipeline…
20
Modelling Projection: glMatrixMode(GL_PPOJECTION);
Transformation
OpenGL doesn't support oblique
Viewing projection
Transformation Only Orthographic parallel & perspective
projections
Projection • Only Orthographic parallel
Transformation
gluOrtho2D (xwmin, xwmax, ywmin, ywmax)
Normalization and glOrtho (xwmin, xwmax, ywmin, ywmax, dnear,
Clipping dfar)
• gluOrtho2D
ViewPort
Transformation
• Intended for use with 2-D graphics
• Defines a world window for clipping that will be
OpenGL Viewing mapped to the specified viewport
Pipline
• No near and far clipping planes
OpenGL viewing pipeline…
21
Modelling • glOrtho (xwmin, xwmax, ywmin, ywmax, dnear,
Transformation dfar)
Viewing – Intended for use with 3-D graphics
Transformation – Defines a world window for clipping that will be
mapped to the specified viewport
Projection
Transformation
– Can also specify near and far clipping planes:
• dnear and dfar are the distances of the clipping
Normalization and planes from the viewing coordinate origin
Clipping along the z-axis
ViewPort
Transformation
OpenGL Viewing
Pipline
OpenGL viewing pipeline…
22
Modelling • Perspective projections
Transformation
gluPerspective (theta, aspect, dnear, dfar)
Viewing glFrustum (xwmin, xwmax, ywmin, ywmax,dnear,
Transformation dfar)
Projection
• gluPerspective
Transformation – theta is the height angle in degrees
– aspect is the ratio of the width to the height of
Normalization and
the image plane (the aspect ratio)
Clipping
– Centre of projection is the origin of the viewing
ViewPort coordinate system
Transformation – dnear, dfar are distances of clipping planes
OpenGL Viewing from centre of projection along z-axis
Pipline – Image plane is the near clipping plane
OpenGL viewing pipeline…
23
Modelling • glFrustum (xwmin, xwmax, ywmin,
Transformation ywmax,dnear, dfar)
Viewing – Corners of near clipping plane have the following
Transformation coordinates in the viewing coordinate system:
• (xwmin, ywmin, -dnear)
Projection
• (xwmin, ywmax, -dnear)
Transformation
• (xwmax, ywmin, -dnear)
Normalization and • (xwmax, ywmax, -dnear)
Clipping
– Centre of projection is the origin of the viewing
coordinate system
ViewPort
Transformation – Image plane is the near clipping plane
OpenGL Viewing
Pipline
OpenGL viewing pipeline(Example)
24
Modelling • gluOrtho2D example:
Transformation • All primitives with (x,y) coordinates between
(0,0) and (640,480) will be displayed
Viewing
glMatrixMode(GL_PROJECTION);
Transformation glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
Projection
Transformation
• glOrtho example:
Normalization and • Defines a 24x24x30 view volume with the
Clipping image plane at the origin:
ViewPort
glMatrixMode(GL_PROJECTION);
Transformation glLoadIdentity();
// arguments are left, right, bottom, top, near, far
OpenGL Viewing glOrtho(-12, 12, -12, 12, 0, 30);
Pipline
OpenGL viewing pipeline(Example…)
25
Modelling •gluPerspective example:
Transformation •Height angle of 45o and aspect ratio of 1.0 width of the image
is the same as the height 45o. The near clipping plane is
Viewing positioned at z=0 and the far clipping plane is at a distance of
Transformation 50 from the camera.
Projection glMatrixMode(GL_PROJECTION);
glLoadIdentity();
Transformation gluPerspective(45, 1.0, 0.0, 50.0);
Normalization and
Clipping • gluFrustum
•Specifies a perspective projection in which the near clipping
ViewPort plane is defined by the four corners (-10, -10, -5), (-10, 10, -5),
Transformation (10, -10, -5) and (10, 10, -5).
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
OpenGL Viewing gluFrustum(-10,10,-10,10,5,50);
Pipline
OpenGL viewing pipeline …
26
Modelling • Viewport: no need for glMatrixMode();
Transformation
• Determines the region of the screen window to be
Viewing used for drawing
Transformation • Specifying the viewport matrix:
• glViewport(xmin, ymin, xsize, ysize);
Projection
Transformation • Viewport has bottom-left corner at (xPos,yPos), and
has a size in pixels of (xSize,ySize)
Normalization and
Clipping
ViewPort glViewport(160, 90, 300, 300);
Transformation
OpenGL Viewing
Pipline
Any Question?
27