1. UNIT III
THREE-DIMENSIONAL
GRAPHICS
Three dimensional concepts; Three dimensional object
representations — Polygon surfaces- Polygon tables- Plane
equations — Polygon meshes; Curved Lines and surfaces,
Quadratic surfaces; Blobby objects; Spline representations —
Bezier curves and surfaces -B-Spline curves and surfaces.
TRANSFORMATION AND VIEWING: Three dimensional
geometric and modeling transformations — Translation,
Rotation, Scaling, composite transformations; Three
dimensional viewing — viewing pipeline, viewing coordinates,
Projections, Clipping; Visible surface detection methods.
1
2. 3D Object Representation
• A surface can be analytically
generated using its function involving
the coordinates.
• An object can be represented in
terms of its vertices, edges and
polygons. (Wire Frame, Polygonal
Mesh etc.)
• Curves and surfaces can also be
designed using splines by specifying
a set of few control points.
2
y = f(x,z)
x y z . . .
3. Solid Modeling - Polyhedron
• A polyhedron is a connected mesh of simple planar polygons
that encloses a finite amount of space.
• A polyhedron is a special case of a polygon mesh that satisfies
the following properties:
• Every edge is shared by exactly two faces.
• At least three edges meet at each vertex.
• Faces do not interpenetrate. Faces at most touch along a
common edge.
• Euler’s formula : If F, E, V represent the number of faces,
vertices and edges of a polyhedron, then
V + F E = 2.
3
4. 3D Object Representation
• The data for polygonal meshes can be represented
in two ways.
• Method 1:
• Vertex List
• Normal List
• Face List (Polygon List)
• Method 2:
• Vertex List
• Edge List
• Face List (Polygon List)
4
8. Normal Vectors (OpenGL)
8
Assigning a normal vector to a polygon:
glBegin(GL_POLYGON);
glNormal3f(xn,yn,zn);
glVertex3f(x1,y1,z1);
glVertex3f(x2,y2,z2);
glVertex3f(x3,y3,z3);
glVertex3f(x4,y4,z4);
glEnd();
Enabling automatic conversion of normal vectors to unit vectors:
glEnable(GL_NORMALIZE);
9. Regular Polyhedra (Platonic Solids)
• If all the faces of a polyhedron are identical, and
each is a regular polygon, then the object is
called a platonic solid.
• Only five such objects exist.
9
10. Wire-Frame Models
• If the object is defined only by a set of nodes
(vertices), and a set of lines connecting the
nodes, then the resulting object representation is
called a wire-frame model.
• Very suitable for engineering applications.
• Simplest 3D Model - easy to construct.
• Easy to clip and manipulate.
• Not suitable for building realistic models.
10
11. Wire Frame Models - OpenGL
11
Some Wireframe Models in OpenGL:
Cube: glutWireCube(Gldouble size);
Sphere: glutWireSphere(…);
Torus: glutWireTorus(…);
Teapot: glutWireTeapot(Gldouble size);
Cone: glutWireCone(…);
(…) Refer text for list of arguments.
13. Polygonal Mesh
• Three-dimensional surfaces and solids can be
approximated by a set of polygonal and line elements.
Such surfaces are called polygonal meshes.
• The set of polygons or faces, together form the “skin”
of the object.
• This method can be used to represent a broad class of
solids/surfaces in graphics.
• A polygonal mesh can be rendered using hidden
surface removal algorithms.
13
15. Solid Modeling
• Polygonal meshes can be used in solid modeling.
• An object is considered solid if the polygons fit together to
enclose a space.
• In solid models, it is necessary to incorporate directional
information on each face by using the normal vector to the
plane of the face, and it is used in the shading process.
15
20. Sweep Representations
• Sweep representations are useful for both surface modeling
and solid modeling.
• A large class of shapes (both surfaces and solid models) can
be formed by sweeping or extruding a 2D shape through
space.
• Sweep representations are useful for constructing 3-D
objects that posses translational or rotational symmetries.
20
21. Extruded Shapes - Examples
21
A polyhedron obtained
by sweeping (extruding)
a polygon along a
straight line is called a
prism.
22. Surface of Revolution
• A surface of revolution is obtained by revolving a curve
(known as the base curve or profile curve) about an axis.
• In other words, a surface of revolution is generated by a
rotational sweep of a 2D curve.
• The symmetry of the surface of revolution makes it a very
useful object in presentation graphics.
22
24. 24
The three-dimensional surface obtained by
revolving the curve y = f(x) about the y-axis is
obtained by replacing x with sqrt(x*x + z*z).
The surface of revolution is thus given by
y f x z
2 2
Surface of Revolution
26. Quad trees
Quad trees are generated by successively dividing
a 2-D region(usually a square) into quadrants.
Each node in the quadtree has 4 data elements,
one for each of the quadrants in the region. If all
the pixels within a quadrant have the same
color (a homogeneous quadrant), the
corresponding data element in the node stores
that color. For a heterogeneous region of space,
the successive divisions into quadrants
continues until all quadrants are homogeneous.
26
27. Octrees
• An octree encoding scheme divide regions of 3-D
space(usually a cube) in to octants and stores 8
data elements in each node of the tree.
• Individual elements of a 3-D space are called
volume elements or voxels.
• When all voxels in an octant are of the same type,
this type value is stored in the corresponding data
element of the node. Any heterogeneous octant is
subdivided into octants and the corresponding
data element in the node points to the next node
in the octree.
27
29. 29
Bezier Curves
The Bezier curve only approximates the control points
and doesn’t actually pass through all of them.
30. 30
Inputs: n control points (xi, yi), i = 0, 1,2, …n-1
,
0
,
0
,
( ) ( )
( ) ( )
0 1
!
( ) (1 )
! !
m
b m i i
i
m
b m i i
i
i m i
m i
x u Bez u x
y u Bez u y
u
m m m
Bez u u u and
i i i m i
m = n1
Bezier Curves
31. 31
Inputs: n control points (xi, yi), i = 0, 1,2, …m
0
( ) ( ) , 0 1
( ) ( ( ), ( ))
( , )
m
m i i
i i
i i i
r u Bez u r u
where
r u x u y u
r x y
Bezier Curves
32. Properties of Bezier Curve
• Bezier curve is a polynomial of degree one less than
the number of control points
32
p0
p2
p1
p0
p2
p1
p3
Quadratic Curve Cubic Curve
33. Properties of Bezier Curve (cont.)
• Bezier curve always passes through the first and
last points; i.e.
and
33
0
(0)
x x
,
0
(0)
y y
(1) m
x x
(1) m
y y
34. Properties of Bezier Curve (cont)
• The slop at the beginning of the curve is along the line
joining the first two control points, and the slope at the end
of the curve is along the line joining the last two points.
34
p0
p2
p1
p0
p2
p1
35. Properties of Bezier Curve (cont)
• Bezier blending functions are all positive and the sum is
always 1.
• This means that the curve is the weighted sum of the
control points.
35
,
0
( ) 1
m
m i
i
Bez u
36. Design Technique using Bezier Curves:
• A closed Bezier curve can be generated by specifying the
first and last control points at the same location
36
p4
p0=p5
p1
p2
p3
37. Design Technique (Cont)
• A Bezier curve can be made to pass closer to a
given coordinate position by assigning multiple
control points to that position.
37
p0
p1 = p2 p3
p4
38. • Bezier curve can be form by piecing of several
Bezier section with lower degree.
38
p0
p1
p2= p’0
p’2
p’3
p’1
39. 39
(Not Important!)
,
0 0
( , ) ( ) ( ) ,
0 1, 0 1
( , ) ( ( , ), ( , ), ( , ))
( , , )
m l
m i l j i j
i j
ij ij ij ij
r u v Bez u Bez v r
u v
where
r u v x u v y u v z u v
r x y z
Bezier Surfaces
40. 40
A set of 16 control points The Bezier Patch
Bezier Patch
43. 3D Translation 1
Translate over vector (tx, ty, tz ):
x’=x+ tx, y’=y+ ty , z’=z+ tz
or
x
y
P
P+T
T
z
z
y
x
t
t
t
z
y
x
z
y
x
T
P
P
T
P
P'
en
,
'
'
'
'
met
,
44. 3D Translation 2
In 4D homogeneous coordinates:
x
y
P
P+T
T
z
1
1
0
0
0
1
0
0
0
1
0
0
0
1
1
'
'
'
or
,
z
y
x
t
t
t
z
y
x
z
y
x
MP
P'
49. 1
3D Rotation around arbitrary axis 1
z
P
x
y
P’
a
Q
2
3
Q)P
)T(
(
T(Q)R
P'
Q
Q
Q
z
a
:
Or
.
over
back
Translate
3.
axis;
-
around
Rotate
2.
;
over
Translate
1.
:
rotation
2D
as
Similar
as.
-
the
example.
For
.
point
through
axis,
coordinate
to
parallel
axis,
around
Rotation
z
-
z
50. z x
y
1
P
2
P
3D Rotation around arbitrary axis 2
Rotation around axis through two points P1 and P1 .
More complex:
1. Translate such that axis goes through origin;
2. Rotate…
3. Translate back again.
51. 3D Rotation around arbitrary axis 3
z x
y
1
P
2
P
Initial
z x
y
'
1
P
1. translate axis
'
P2
z x
y
2. rotate axis
'
1
P
'
'
P2
z x
y
3. rotate around
z-axis
'
1
P
'
'
P2
4. rotate back
z x
y
'
1
P
'
P2
z x
y
1
P
2
P
5. translate back
52. 3D Rotation around arbitrary axis 3
z x
y
1
P
2
P
Initial
z x
y
'
1
P
1. translate axis
'
P2
z x
y
2. rotate axis
'
1
P
'
'
P2
z x
y
3. rotate around
z-axis
'
1
P
'
'
P2
4. rotate back
z x
y
'
1
P
'
P2
z x
y
1
P
2
P
5. translate back
T(P1) R
Rz(a)
R1
T(P1)
53. 3D Rotation around arbitrary axis 3
z x
y
1
P
2
P
Initial
z x
y
'
1
P
1. translate axis
'
P2
z x
y
2. rotate axis
'
1
P
'
'
P2
z x
y
3. rotate around
z-axis
'
1
P
'
'
P2
4. rotate back
z x
y
'
1
P
'
P2
z x
y
1
P
2
P
5. translate back
T(P1) R
Rz(a)
R1
T(P1)
M = T(P1) R1Rz(a) RT(P1)
54. 3D Rotation around arbitrary axis 4
z x
y
'
1
P
'
P2
z x
y
2. rotate axis
'
1
P
'
'
P2
Difficult step:
Find rotation such that rotation axis aligns with z-axis.
Two options:
1. Step by step by step (see H&B, 309-312)
2. Direct derivation of matrix
R
55. 3D Rotation around arbitrary axis 5
z
x
y
u
v
w
1. Construct orthonormal axis frame u, v, w;
2. Invent rotation matrix R, such that:
u is mapped to z-axis;
v is mapped to y-axis;
w is mapped to x-axis.
56. 3D Rotation around arbitrary axis 6
z
x
y
u
v
w
Construct orthonormal axis frame u, v, w:
u = (P2P1) / |P2P1|
v = u (1,0,0) / | u (1,0,0) |
w = v u
(If u = (a, 0, 0), then use (0, 1, 0))
This frame is orthonormal:
Unit length axes: u.u = v.v = w.w = 1
All axes perpendicular: u.v = v.w = w.u = 0
57. 3D Rotation around arbitrary axis 7
z
x
y
u
v
w
1
0
0
1
1
and
,
1
0
1
0
1
,
1
1
0
0
1
such that
in
Fill
1
0
0
0
0
0
0
:
matrix
rotation
Generic
33
32
31
23
22
21
13
12
11
z
y
x
z
y
x
z
y
x
w
w
w
v
v
v
u
u
u
r
r
r
r
r
r
r
r
r
R
R
R
R
R
58. 3D Rotation around arbitrary axis 8
z
x
y
u
v
w
Done! But how to find R1 ?
1
0
0
0
0
0
0
:
Solution
1
0
0
1
1
and
,
1
0
1
0
1
,
1
1
0
0
1
such that
,
Fill
z
y
x
z
y
x
z
y
x
z
y
x
z
y
x
z
y
x
u
u
u
v
v
v
w
w
w
w
w
w
v
v
v
u
u
u
R
R
R
R
R
60. Requested: M-1 such that M-1M = I
Solution:
In words:
The inverse of a rotation matrix is the transpose.
(For a rotation around the origin).
z
y
x
z
y
x
z
y
x
T
T
T
T
w
w
w
v
v
v
u
u
u
1
w
v
u
M
M
Inverse of rotation matrix 2
61. I
w
w
v
w
u
w
w
v
v
v
u
v
w
u
v
u
u
u
w
v
u
w
v
u
M
M
1
0
0
0
1
0
0
0
1
T
T
T
T
Requested: M-1 such that M-1M = I
Solution: M-1 = M-T
Check:
Inverse of rotation matrix 3
63. More 3D transformations
+/- same as in 2D:
• Matrix concatenation by multiplication
• Reflection
• Shearing
• Transformations between coordinate systems
65. Affine transformations 2
Properties:
1. Transformed coordinates x’,y’ and z’ are linearly
dependent on original coordinates x, y en z.
2. Parameters aij en bk are constant and determine type
of transformation;
3. Examples: translation, rotation, scaling, reflection
4. Parallel lines remain parallel
5. Only translation, rotation reflection: angles and
lengths are maintained
66. 3D Viewing
• Viewing: virtual camera
• Projection
• Depth
• Visible lines and surfaces
• Surface rendering
67. 3D Viewing pipeline 1
• Similar to making a photo
– Position and point virtuele camera, press button;
Projection plane aka
Viewing plane
• Pipeline has +/ same structure as in 2D
68. 3D Viewing pipeline 2
MC: Modeling Coordinates
WC: World Coordinates
VC: Viewing Coordinates
PC: Projection Coordinates
NC: Normalized Coordinates
DC: Device Coordinates
Apply model transformations
To camera coordinates
Project
To standard coordinates
Clip and convert to pixels
69. 3D viewing coordinates 1
Specification of projection:
P0 : View or eye point
Pref : Center or look-at point
V: View-up vector
(projection along vertical
axis)
zvp : positie view plane
P0
zw
yw
xw
Pref
N
V
P0, Pref , V: define viewing coordinate system
Several variants possible
70. 3D viewing coordinates 2
P0
zw
yw
xw
Pref
N
V
zview
yview
xview
P0, Pref , V: define viewing coordinate system
Several variants possible
71. 3D view coordinates 3
P0
zw
yw
xw
Pref
N
V
zview
yview
xview
u
)
,
,
(
:
and
lar to
perpendicu
z
y
x u
u
u
V
n
V
u
n
V
u
v
)
,
,
(
:
and
lar to
perpendicu
z
y
x v
v
v
u
n
v
u
n
v
)
,
,
(
:
frame
axis
Derivation
ref
0
z
y
x n
n
n
N
N
n
P
P
N
n
72. 3D viewing coördinaten 4
P0
zw
yw
xw
Pref
N
V
zview
yview
xview
n
u
v
RT
M
R
R
P
T 0
W C,VC
z
y
x
z
y
x
z
y
x
n
n
n
v
v
v
u
u
u
:
Or
1
0
0
0
0
0
0
:
with
rotate
Next,
)
(
with
translate
First,
:
view
tion world
Transforma
74. Orthogonal projections 1
P’1
P’2
Parallell projection:
Projection lines are parallel
Orthogonal projection:
Projection lines are parallel and
perpendicular to projection plane
Isometric projection:
Projection lines are parallel,
perpendicular to projection plane,
and have the same angle with axes.
P1
P2
P’1
P’2
P1
P2
x
y
z
75. Orthogonal projections 2
Orthogonal projection:
P’1
P’2
P1
P2
Trivial!
:
s)
coordinate
projection
to
s
coordinate
view
(from
)
,
,
(
of
Projection
z
z
y
y
x
x
z
y
x
p
p
p
80. Perspective projection 2
P = (x, y, z) R: Projection reference point
zview
xview
yview
(xr, yr, zr)
(xp, yp, zp)
To simplify,
Assume R in origin
View plane: z = zvp
Question: What is the projection of P
on the view plane?
81. Perspective projection 3
P = (x, y, z)
zview
xview
yview
(xp, yp, zp)
(0,0, 0)
R=
.
'
and
;
'
;
'
or
,
1
0
with
,
'
:
to
(origin)
from
Line
uz
z
uy
y
ux
x
u
u
P
X
P
R
.
hence
'
:
plane
with
crossing
At
z
z
u
z
z
vp
vp
y
z
z
y
x
z
z
x
vp
p
vp
p
and
gives
on
Substituti
View plane: z = zvp
82. Perspective projection 4
P = (x, y, z) View plane
zview
yview
Viewed from the side
R
z
y
zvp
yp
y
z
z
y
z
y
z
y
vp
p
vp
p
hence
:
that
see
can
We
83. Perspective projection 5
P = (x, y, z)
Clipping window
in View plane
zview
yview
R
zvp
W
wmax
wmin
Ratio between
W=wmaxwmin and zvp
determines strenght perspective
Viewed from the side
84. Viewed from the side
Perspective projection 6
Clipping window
in View plane
zview
yview
R
Ratio between
W=wmaxwmin and zvp
determines strenght perspective.
This ratio is 2tan(/2),
with the view angle.
89. Perspective projection 9
zview
yview
R
zvp
W
Use camera as metaphor. User specifies focal length f .
(20 mm – wide angle, 50 mm – normal, 100 mm – tele).
Application adjusts W and/or zvp, such that W/zvp = 24/f.
For x: W/zvp = 36/f.
f (mm)
24 mm
93. Side view Front view
Perspective projection 10
yview
R
zview
znorm
ynorm
Perspective transformation:
Distort space, such that perpendicular projection gives
an image in perspective.
96. (r, r, zn)
(rzf /zn, rzf /zn, zf )
Perspective projection 11
yview
R
zview
znorm
ynorm
(1, 1, 1)
(1,1,1)
How to put this transformation in the pipeline?
How to process division by z?
Earlier: y
z
z
y
x
z
z
x
vp
p
vp
p
,
97. Homogeneous coordinates (reprise)
• Add extra coordinate:
P = (px , py , pz , ph) or
x = (x, y, z, h)
• Cartesian coordinates: divide by h
x = (x/h, y/h, z/h)
• Points: h = 1 (temporary…)perspective: h = z !
99. Perspective projection 12
xview
R
zview
znorm
ynorm
(r, r, zn)
(rzf /zn, rzf /zn, zf )
(1, 1, 1)
(1,1,1)
(r, r, zn)
.
0
,
/
:
gives
n
Elaboratio
.
1
also
then
,
and
/
If
.
1
then
,
and
If
.
/
)
(
is
form
Generic
.
First
x
xz
xy
n
xx
p
f
n
f
p
n
x
xz
xy
xx
p
t
s
s
r
z
s
x
z
z
z
rz
x
x
z
z
r
x
z
t
z
s
y
s
x
s
x
x
100. Perspective projection 13
yview
R
zview
znorm
ynorm
(r, r, zn)
(rzf /zn, rzf /zn, zf )
(1, 1, 1)
(1,1,1)
.
0
),
/
(
:
Or
.
/
)
/
(
:
gives
,
as
Same
.
Next the
y
yz
yx
n
yy
n
p
t
s
s
r
z
s
z
y
r
z
y
x
y
101. Perspective projection 14
yview
R
zview
znorm
ynorm
(r, r, zn)
(rzf /zn, rzf /zn, zf )
(1, 1, 1)
(1,1,1)
.
0
,
2
,
gives
n
Elaboratio
.
1
then
,
If
.
1
then
,
If
.
/
)
(
:
is
form
Generic
.
:
Finally
zy
zx
f
n
f
n
z
f
n
f
n
zz
f
f
p
n
z
zz
zy
zx
p
s
s
z
z
z
z
t
z
z
z
z
s
z
z
z
z
z
z
z
t
z
s
y
s
x
s
z
z
103. 3D Viewport coordinates 1
znorm
xnorm
ynorm
Normalized View volume
(1,1,1)
(1, 1, 1)
zv xv
yv
3D screen
(xvmin, yvmin, 0)
(xvmax, yvvmax, 1)
scaling
translation
104. 3D Viewport coordinaten 2
1
1
0
0
0
2
1
2
1
0
0
0
0
2
0
0
0
0
2
:
s
coordinate
screen
3D
to
s
coordinate
view
normalized
from
tion
Transforma
min
max
min
max
p
p
p
s
s
s
z
y
x
yv
yv
xv
xv
h
z
y
x
105. OpenGL 3D Viewing 1
3D Viewing in OpenGL:
• Position camera;
• Specify projection.
106. OpenGL 3D Viewing 2
z
x
y
View volume
Camera always in origin, in direction of negative z-axis.
Convenient for 2D, but not for 3D.
107. OpenGL 3D Viewing 3
Solution for view transform: Transform your model
such that you look at it in a convenient way.
Approach 1: Do it yourself. Apply rotations,
translations, scaling, etc., before rendering the
model. Surprisingly difficult and error-prone.
Approach 2: Use gluLookAt();
109. OpenGL 3D Viewing 5
z
x
y
Orthogonal projection:
MatrixMode(GL_PROJECTION);
glOrtho(xwmin, xwmax, ywmin, ywmax, dnear, dfar);
xwmin
xwmax
ywmin
ywmax
xwmin, xwmax, ywmin,ywmax:
specification window
dnear: distance to near clipping plane
dfar : distance to far clipping plane
Select dnear and dfar right:
dnear < dfar,
model fits between clipping planes.
110. OpenGL 3D Viewing 6
Perspective projection:
MatrixMode(GL_PROJECTION);
glFrustrum(xwmin, xwmax, ywmin, ywmax, dnear, dfar);
xwmin
xwmax
ywmin
ywmax
xwmin, xwmax, ywmin,ywmax:
specification window
dnear: distance to near clipping plane
dfar : distance to far clipping plane
z
x
y
Standard projection: xwmin = -xwmax,
ywmin = -ywmax
Select dnear and dfar right:
0 < dnear < dfar,
model fits between clipping planes.
111. OpenGL 3D Viewing 7
Finally, specify the viewport (just like in 2D):
glViewport(xvmin, yvmin, vpWidth, vpHeight);
xvmin, yvmin: coordinates lower left corner (in pixel coordinates);
vpWidth, vpHeight: width and height (in pixel coordinates);
(xvmin, yvmin)
vpWidth
vpHeight
113. Visibility
Assumption: All polygons are opaque
What polygons are visible with respect to your view frustum?
Outside: View Frustum Clipping
Remove polygons outside of the view volume
For example, Liang-Barsky 3D Clipping
Inside: Hidden Surface Removal
Backface culling
Polygons facing away from the viewer
Occlusion
Polygons farther away are obscured by closer polygons
Full or partially occluded portions
Why should we remove these polygons?
Avoid unnecessary expensive operations on these polygons later
117. Occlusion: Full, Partial, None
Full Partial None
l The rectangle is closer than the triangle
l Should appear in front of the triangle
118. Backface Culling
Avoid drawing polygons facing away from the viewer
Front-facing polygons occlude these polygons in a closed
polyhedron
Test if a polygon is front- or back-facing?
front-facing
back-facing
Ideas?
119. Detecting Back-face Polygons
The polygon normal of a …
front-facing polygon points towards the viewer
back-facing polygon points away from the viewer
If (n v) > 0 “back-face”
If (n v) ≤ 0 “front-face”
v = view vector
Eye-space test … EASY!
“back-face” if nz < 0
glCullFace(GL_BACK)
back
front
120. Polygon Normals
Let polygon vertices v0, v1, v2,..., vn - 1 be in
counterclockwise order and co-planar
Calculate normal with cross product:
n = (v1 - v0) X (vn - 1 - v0)
Normalize to unit vector with n/║n║
v0
v1
v2
v3
v4
n
121. Normal Direction
Vertices counterclockwise Front-facing
Vertices clockwise Back-facing
0
1
2
0
2
1
Front facing Back facing
122. Painter’s Algorithm (1)
Assumption: Later projected polygons overwrite earlier
projected polygons
Graphics Pipeline
1 1
2 2
3 3
Oops! The red polygon
Should be obscured by
the blue polygon
123. Painter’s Algorithm (2)
Main Idea
A painter creates a picture
by drawing background
scene elemens before
foreground ones
Requirements
Draw polygons in back-to-
front order
Need to sort the polygons
by depth order to get a
correct image
from Shirley
127. Painter’s Algorithm (6)
Cyclic Overlap
How do we sort these three polygons?
Sorting is nontrivial
Split polygons in order to get a total ordering
Not easy to do in general
128. Visibility
How do we ensure that closer polygons
overwrite further ones in general?
129. Z-Buffer
Depth buffer (Z-Buffer)
A secondary image buffer that holds depth values
Same pixel resolution as the color buffer
Why is it called a Z-Buffer?
After eye space, depth is simply the z-coordinate
Sorting is done at the pixel level
Rule: Only draw a polygon at a pixel if it is closer
than a polygon that has already been drawn to
this pixel
132. Z-Buffer
How do we calculate the depth values on the polygon interior?
P1
P2
P3
P4
ys za zp zb
Scanline order
)
(
)
(
)
(
)
(
)
(
)
(
)
(
)
(
)
(
b
a
p
a
a
b
a
p
s
b
s
a
x
x
x
x
z
z
z
z
y
y
y
y
z
z
z
z
y
y
y
y
z
z
z
z
2
1
1
1
2
1
4
1
1
1
4
1
Bilinear Interpolation
137. Z-buffering in OpenGL
Create depth buffer by setting GLUT_DEPTH flag in
glutInitDisplayMode()or the appropriate
flag in the PIXELFORMATDESCRIPTOR.
Enable per-pixel depth testing with
glEnable(GL_DEPTH_TEST)
Clear depth buffer by setting GL_DEPTH_BUFFER_BIT
in glClear()