Computer Graphics
Lecture 3
Graphics Output Primitives
Somsak Walairacht, Computer Engineering, KMITL
Fill-Area Primitives
Area filled with solid color or pattern
Most graphics require a fill area be a polygon
Curved surfaces can be approximated with
a set of polygon patches
Sometimes called as surface tessellation
Computer Graphics
2
Polygon
Computer Graphics
A polygon is a plane figure specified by a set
of three or more coordinate positions, called
vertices
A polygon must have all its vertices within a
single plane and there can be no edge
crossings
To avoid ambiguous object references,
“polygon” refers only to those planar shapes
that have a closed-polyline boundary and no
edge crossings
3
Convex vs. Concave
Convex :
All interior angles < 180 degree, and
All line segments between 2 interior points in polygon, and
All points at the same side of line through edge, and
From each interior point complete boundary visible
Concave : not convex
H&B 4-7:84-94
Identifying Concave Polygons
A concave polygon has at least one interior angle
greater than 180
Extension of some edges intersect other edges
Computer Graphics
Line segment by a pair of interior points intersects the
polygon boundary
The cross product of adjacent edges is used to test
for concavity
5
Splitting Concave Polygons
Computer Graphics
Using edge vectors and edge cross
products
If any cross product has a negative z,
we can split it along the line of the first
edge vector in the cross-product pair
6
Splitting Concave Polygons (2)
Computer Graphics
Using a rotational method
Proceeding counterclockwise around the
polygon edges, shift the position of the
polygon so that each vertex Vk in turn is
at the coordinate origin
Rotate the polygon about the origin in a
clockwise direction so that the next
vertex Vk+1 is on the x-axis
7
Splitting Concave Polygons (3)
Computer Graphics
If the following vertex, Vk+2, is below the
x-axis, then split the polygon along the xaxis
Steps are repeated until all vertices in the
polygon list are tested
8
Splitting a Convex Polygon
into a Set of Triangles
Computer Graphics
Defining any sequence of 3 consecutive
vertices to be a new polygon (a
triangle)
The middle triangle vertex is then
deleted from the original vertex list
Repeat until the original polygon is
reduced to just three vertices
9
Inside-Outside Tests
Odd-even rule, also called the odd-parity rule or the
even-odd rule
Identifying interior areas of a plane figure
Drawing a line from any position P to a distant point
outside the coordinate extents of the closed polyline
Then count the number of line-segment crossings
along this line
Odd=interior, otherwise = exterior
Computer Graphics
10
Inside-Outside Tests (2)
Nonzero winding-number rule
Counts the number of times the boundary of an
object “winds” around a particular point in the
counterclockwise direction
The interior points of a 2D object can be defined by
having a nonzero value for the winding number
Nonzero = interior, otherwise = exterior
Computer Graphics
11
Nonzero Winding-Number
Rule Mechanism
Initializing the winding number to 0
A line drawn from any position P to a distant
point beyond the coordinate extents of the
object
Count the number of object line segments
that cross the reference line in each direction
Computer Graphics
Add 1 when intersects a segment that crosses
from right to left (counterclockwise)
Subtract 1 when intersects a segment that crosses
from left to right (clockwise)
12
Variations of the Nonzero
Winding-Number Rule
Border direction
Winding number
Add 1 (counterclockwise)
Subtract 1 (clockwise)
Computer Graphics
13
Polygon Tables
Objects in scene are described as a set of polygon
surface facets
Geometric data for objects in scene are arranged in
Computer Graphics
Vertex table, store the coordinate value of vertex
Edge table, contains pointers back into the vertex table
to identify the vertices for each polygon edge
Surface-facet table, contains pointers back into the
edge table to identify the edge for each polygon edge
Edge table can be expanded to include forward
pointers into the surface-facet table
14
Polygon Tables (2)
Computer Graphics
Polygon table for two adjacent polygon surface facets
Convenient reference
Object can be displayed efficiently
15
Polygon Tables (3)
Computer Graphics
Tables can be organized into two groups:
geometric tables and attribute tables
Geometric tables contain vertex coordinates
and parameters to identify the spatial
orientation of the polygon surfaces
Attribute tables specify the degree of
transparency of the object and its surface
reflectivity and texture characteristics
16
Plane Properties
ax1 by1 cz1 d 0
ax2 by2 cz2 d 0
General equation of a plane ax by cz d 0
Use Cramer’s rule to compute polygon facets data
1
a
y1
d
1 y2
D
1 y3
z1
z2 , b
z3
x1 1 z1
d
d
x2 1 z 2 , c x 2
D
D
x3 1 z3
x3
Distance
x1
y1
z1
y 2 1 , D x2
y2
z2
y3 1
y3
z3
x3
p1 ( x1 , y1 , z1 )
ax1 by1 cz1 d
a 2 b2 c 2
Front and back polygon faces
Computer Graphics
y1 1
Distance from a point to a plane
ax by cz d 0,
x1
ax3 by3 cz3 d 0
Back face, side of polygon faces into the object interior
Front face, the visible or outward side
17
Plane Properties (2)
Identify a point behind or in front of a polygon
surface
Put the point into the plane equation
if Ax + By + Cz +D < 0, the point (x,y,z) is behind the plane
if Ax + By + Cz +D > 0, the point (x,y,z) is in front of the plane
Computer Graphics
Orientation of a polygon surface in space, described by
normal vector
18
Computer Graphics
Chapter 4
Attributes of Graphics Primitives
Somsak Walairacht, Computer Engineering, KMITL
19
Point Attributes
Two attributes for points:
Computer Graphics
color and size
Color components are set with RGB
values or an index into a color table
Size is an integer multiple of the pixel
size
20
Line Attributes
Three basic attributes:
Additionally, lines may be generated
with other effects, such as
Computer Graphics
color, width, and style
pen and brush strokes
21
Fill-Area Attributes
Computer Graphics
Most graphics packages limit fill areas
to polygons, because they are described
with linear equations
Further restriction requires fill areas to
be convex
22
Point Attributes
Two attributes for points:
Computer Graphics
color and size
Color components are set with RGB
values or an index into a color table
Size is an integer multiple of the pixel
size
23
Line Attributes
Three basic attributes:
Additionally, lines may be generated
with other effects, such as
Computer Graphics
color, width, and style
pen and brush strokes
24
Fill-Area Attributes
Computer Graphics
Most graphics packages limit fill areas
to polygons, because they are described
with linear equations
Further restriction requires fill areas to
be convex
25
Fill-Area Attributes (2)
There are two basic procedures for filling an
area on raster systems
1 (simple shape)
2 (not so simple shape)
Computer Graphics
Determines the overlap intervals for scan lines
that cross the area
Pixel positions along these overlap intervals are
set to the fill color
Start from a given interior position and “paint”
outward pixel-by-pixel until boundary
26
Fill-Area Attributes (3)
The scan-line approach is usually
applied to simple shapes such as circles
or regions with polyline boundaries
Computer Graphics
General graphics packages use this fill
method
While using a starting interior point, it is
useful for filling areas with more
complex boundaries and in interactive
painting systems
27
Color-Blended Fill Regions
Foreground color (or pattern) could be
combined with background colors
Using a transparency factor that
determines how much of the background
should be mixed with the object color
1.0 representing complete opacity
0.0 representing complete transparency
www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
Computer Graphics
28
Color-Blended Fill Regions (2)
Computer Graphics
Simple logical or replace operations
29
1. General Scan-Line PolygonFill Algorithm
Computer Graphics
A scan-line fill of a region is performed by
first determining the intersection positions of
the boundaries of the fill region with the
screen scan lines
Then the fill colors are applied to each section
of a scan line that lies within the interior of
the fill region
The scan-line fill algorithm identifies the same
interior regions as the odd-even rule
30
General Scan-Line Polygon-Fill
Algorithm (2)
Basic scan-line procedure: 2 steps
1. Edge intersections are sorted from left to right
2. The pixel positions between, and including, each
intersection pair are set to the specified fill color
3
2
4
5
1
Sort x-intersection ascending
Computer Graphics
31
General Scan-Line Polygon-Fill
Algorithm (3)
To split those vertices that should be counted as one
intersection
When the endpoint y coordinates of the two edges are
increasing, the y value of the upper endpoint for the current
edge is decreased by 1
preserves the order
When the endpoint y values are monotonically decreasing, the y
coordinate of the upper endpoint of the edge following the
current edge is decreased by 1
next
current
Computer Graphics
current
next
32
General Scan-Line Polygon-Fill
Algorithm (4)
การเกี่ยวพัน,การเชื่อมโยง
Computer Graphics
Coherence properties can be used in
computer-graphics algorithms to reduce
processing
It often involves incremental
calculations applied along a single scan
line or between successive scan lines
33
Determining Fill-Area Edge
Intersections
Two successive scan lines crossing the left
edge of a triangle
The slope of this edge
m = (yk+1−yk)/(xk+1−xk)
The change in y coordinates
yk+1−yk = 1
Each successive x intercept can thus be
calculated by adding the inverse of the slope
and rounding to the nearest integer
xk+1 = xk+1/m
Computer Graphics
34
Coherence Methods
Method 1
m=7/3
int counter, dx, dy
counter = 0
counter += dx
If counter ≥ dy then {
x++, counter -= dy }
y++
Method 2
counter = 0
counter += 2dx
If counter ≥ dy then {
x++, counter -= 2dy }
y++
[1]
Computer Graphics
[2]
35
2. Sorted Edge Table
Proceeding around the edges in
either a clockwise or a
counterclockwise order, sorted on
the smallest y value of each edge
Only nonhorizontal edges are
entered into the table
For a particular scan line, stores
the maximum y value for that edge,
the x-intercept value (at the lower
vertex) for the edge,
the inverse slope of the edge
For each scan line, the edges are in
sorted order from left to right
Computer Graphics
36
Sorted Edge Table (2)
Process the scan lines from
the bottom of the polygon
to its top -> active edge
list for each scan line
For a scan line contains all
edges crossed, uses
iterative coherence
calculations to obtain the
edge intersections
For each scan line, fill
interior pixel at x-intercept
values from left to right
Computer Graphics
37
3. Scan-Line Fill of Convex
Polygons
Uses coordinate extents to determine which
edges cross a scan line
Intersection calculations with these edges
then determine the interior pixel span
Any vertex crossing is counted as a single
point
Some graphics packages restrict fill areas to
be triangles
Computer Graphics
This makes filling even easier
38
4. Scan-Line Fill for Regions
with Curved Boundaries
Computer Graphics
For simple curves such as circles or ellipses, apply fill
methods for convex polygons
Each scan line cross just two boundary intersections
Determine these two intersection points using the
incremental calculations in the midpoint method
Simply fill in the horizontal pixel spans
Applies symmetric property between quadrants
39
5. Fill Methods For Areas with
Irregular Boundaries
Computer Graphics
Boundary-fill algorithm, is employed in
interactive painting packages, where
interior points are easily selected
Select a fill color, specify the boundary
color, and pick an interior point
40
Fill Methods For Areas with
Irregular Boundaries (2)
Two methods for processing
neighboring pixels from a
current test position
Computer Graphics
4-connected : pixel positions that
are right, left, above, and below
the current pixel
8-connected : Neighboring
positions to be tested includes the
four diagonal pixels
41
6. Boundary Fill
Computer Graphics
42
7. Flood-Fill Algorithm
Computer Graphics
Paints areas by replacing a specified interior color
instead of searching for a particular boundary color
Starting from a specified interior point (x, y) and
reassign all pixel values to a given interior color
Using either a 4-connected or 8-connected approach
43
8. Character Rendering
Letters, digits, non-alphanumeric
Font – overall design style of a set of characters
Fonts can vary in appearance
Bitmap font
Outlined fonts - Examples are PostScript Type 1, Type 3 fonts,
TrueType and OpenType
Font size usually denoted in point (e.g. 10-point, 12-point)
Computer Graphics
Normal, Bold, Italic
Rendering techniques
Times New Roman, Courier, Arial
Denotes height of the characters in inches
1 DTP point = 1/72 of an inch or approx 0.0139 inch
44
Character Attributes (2)
Computer Graphics
The orientation for a character string
can be set according to the direction of
a character up vector
45
Aliasing
Computer Graphics
Jagged or stair-step appearance
happens because the sampling process
digitizes coordinate points on an object
to discrete integer pixel positions
This distortion due to low-frequency
sampling (undersampling) is called
aliasing
46
Antialiasing
To increase sampling rate, simply
displays objects at higher resolution
Limitations:
Modify pixel intensities
Computer Graphics
How big the frame buffer
Refresh rate 60 fps (Hz) or more
Appropriately varying the intensities of
pixels along the boundaries of primitives
47
Antialiasing (2)
Pre-filtering
Post-filtering
Computer Graphics
Filter before sampling- determine pixels
from the continuous signal
Disadvantage: percent calculation
introduces complexity
Filter after sampling- determine pixels from
the discreet samples of the continuous
signal
48
Antialiasing (3)
Supersampling (or Post-filtering)
Area sampling (or Pre-filtering)
by calculating the areas of overlap of each pixel with the
objects to be displayed
Pixel phasing
Computer Graphics
use multiple sample points across the finer grid to determine
an appropriate intensity level for each screen pixel
Hardware approach
by shifting the display location of pixel areas
(“micropositioning” the electron beam in relation to object
geometry)
49
Supersampling Straight-Line
Segments
Divide each pixel into a number of subpixels and
count the number of subpixels that overlap the line
path
The intensity level for each pixel is then set to a
value that is proportional to this subpixel count
1
2
3
Computer Graphics
2
1
50
Supersampling Straight-Line
Segments : Advantage
Computer Graphics
Represent the line with finite width
The number of possible intensity levels for
each pixel is equal to the total number of
subpixels within the pixel area
51
Supersampling Straight-Line
Segments : Advantage (2)
Since a particular line might cross several
different color areas
We can average subpixel intensities to obtain
pixel color settings
Computer Graphics
Ex. 5 subpixels within a particular pixel area are
determined to be inside a red line and the
remaining 4 subpixels fall within a blue
background
pixelcolor = (5 · red + 4 · blue) / 9
52
Subpixel Weighting Mask
By giving more weight to subpixels near the center of
a pixel area
Since these subpixels are to be more important in
determining the overall intensity of a pixel
Intensities calculated for each of the 9 subpixels
Computer Graphics
Center subpixel is weighted by a factor of 1/4
Top, bottom, and side subpixels are each of 1/8
Corner subpixels are each weighted by 1/16
53
Area Sampling Straight-Line
Segments
Computer Graphics
A method for estimating pixel overlap areas
The pixel with grid coordinates (10, 20) is about 90%
covered by the line area, so its intensity would be set
to 90% of the maximum intensity
Similarly (10, 21) would be set to 15%
54
Pixel Phasing
Computer Graphics
With the technique by moving
(micropositioning) pixel positions closer
to the line path
The electron beam is typically shifted by
¼, ½, or ¾ of a pixel diameter to plot
points closer to the true path of a line
or object edge
55
Pixel Phasing (2)
Computer Graphics
56
Compensating for Line
Intensity Differences
Computer Graphics
The diagonal line is longer than the
horizontal line by a factor of 2
By adjusting the intensity of each line
according to its slope
Horizontal and vertical lines would be
displayed with the lowest intensity,
while 45◦ lines would be given the
highest intensity
57
End of Lecture 4
Computer Graphics
58
© Copyright 2026 Paperzz