1 eel 5771-001 introduction to computer graphics ppt2: graphics output primitives by arunbalaji...
TRANSCRIPT
![Page 1: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/1.jpg)
1
EEL 5771-001Introduction to Computer Graphics
PPT2: Graphics Output Primitives
ByArunbalaji Prithiviraj
(U80066848)
![Page 2: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/2.jpg)
2
Outline
• Coordinate Frames• Line Drawing Algorithms• Circle Algorithms• Ellipse Algorithms• Pixel Addressing• Area Fill Methods• Plane Equations• OpenGL Area Fill• Vertex Arrays• Pixel Array• Character Handling
![Page 3: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/3.jpg)
3
Coordinate Frames
![Page 4: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/4.jpg)
4
Coordinate Frames
• Coordinate frames can be any convenient Cartesian coordinate system, called the world-coordinate reference frame, which could be either two dimensional or three-dimensional.
– For instance, we define a straight-line segment with two endpoint positions, and a polygon is specified with a set of positions for its vertices.
• Screen coordinates represents the pixel positions in the frame buffer.– For example, we could specify an integer range for screen positions with the
coordinate origin at the lower-left of a screen area, or we could use non integer Cartesian values for a picture description.
![Page 5: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/5.jpg)
5
Graphics programing: Points
• Plotting points give a coordinate positions in the world reference frame.
– for a random-scan CRT, deflect and activate the electron beam– for a raster scan CRT, set a bit or byte at the appropriate location in the
frame buffer.– Attributes: Size, Color
glPointSize(p);glBegin(GL_POINTS);
glVertex2d(x1, y1);glVertex2d(x2, y2);glVertex2d(x3, y3);
glEnd()
![Page 6: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/6.jpg)
6
Graphics programing: Lines
• Plotting Lines specify the end points coordinates of each line segment– analog devices (random-scan CRTs, etc.)– digital devices (raster-scan CRTs, plasma panels, pen plotters) use pixels
near the true line, resulting in the “jaggies”– Attributes: Color, Thickness, Type
glLineWidth(p);glBegin(GL_LINES);
glVertex2d(x1, y1);glVertex2d(x2, y2);glVertex2d(x3, y3);glVertex2d(x4, y4);
glEnd()
![Page 7: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/7.jpg)
7
Line drawing algorithm
![Page 8: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/8.jpg)
8
Line Drawing Algorithms
• The math behind a simple line drawing algorithm
bxmy .
0
0
xx
yym
end
end
Y intercept
slope
![Page 9: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/9.jpg)
9
Line Drawing Algorithms : Digital differential analyzer (DDA)
• line equation: y = m. x + b
m
m
yx
xy
.
X,Y interval
• DDA (digital differential analyzer)
![Page 10: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/10.jpg)
10
Line Drawing Algorithms : Digital differential analyzer (DDA)
• Algorithm is an incremental scan conversion method.• Based on calculating either or• If |m|<1,
myy
xmy
kK
1
)1( x
![Page 11: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/11.jpg)
11
Line Drawing Algorithms : Digital differential analyzer (DDA)
• If |m|>1, )1( y
If
mxx
m
yx
kK
11
)1( x
myy
xmy
kK
1
![Page 12: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/12.jpg)
12
Line Drawing Algorithms : Bresenham’s algorithm
• Uses only integer calculations for efficiency • Given a pixel which is known, there are really only two possibilities for the next one.• faster than simple DDA• incremental integer calculations
– adaptable to circles, other curves
![Page 13: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/13.jpg)
13
Line Drawing Algorithms : Bresenham’s algorithm
•By testing the sign of an integer parameter, whose value is proportional to the difference between the separation of two pixel positions from the actual line path.
![Page 14: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/14.jpg)
14
Line Drawing Algorithms : Bresenham’s algorithm
![Page 15: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/15.jpg)
15
Line Drawing Algorithms : Bresenham’s algorithm
![Page 16: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/16.jpg)
16
Line Drawing Algorithms : Bresenham’s algorithm
y
yk
yk+1
xk+1
}
}d2
d1
![Page 17: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/17.jpg)
17
Line Drawing Algorithms : Bresenham’s algorithm
d1 = y - yk = m (xk + 1) + b - yk
d2 = (yk + 1) - y = yk + 1 - m (xk + 1) –b
d1 - d2 = 2 m (xk + 1) - 2 yk + 2b -1
![Page 18: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/18.jpg)
18
Line Drawing Algorithms : Bresenham’s algorithm
Pk = ΔX ( d1 - d2) = 2 ΔY . xk - 2 ΔX . yk + c
c = constant = 2 ΔY + ΔX (2b -1)
![Page 19: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/19.jpg)
19
Line Drawing Algorithms : Bresenham’s algorithm
Let's get rid of multiplicationsPk+1 = 2 ΔY . xk+1 - 2 ΔX .y + c
Pk+1 - Pk = 2 ΔY (xk+1 - xk) -2 ΔX (yk+1 - yk) (get rid of the constant)
Pk+1 = Pk + 2 ΔY - 2 ΔX (yk+1 - yk)
Pk+1 = Pk + 2ΔY or = Pk + 2(ΔY – ΔX(
with (yk+1 - yk) = 0 or 1 depending on Pk sign
![Page 20: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/20.jpg)
20
Line Drawing Algorithms : Bresenham’s algorithm
P0 =ΔX (d1-d2) =ΔX[2m(x0+1)-2y0+2b-1] =ΔX[2(mx0+b-y0)+2m-1]
P0=2ΔY -ΔX
![Page 21: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/21.jpg)
21
Line Drawing Algorithms : Bresenham’s algorithm
Example: Digitize the line with endpoint (20,10) and (30,18) ΔX=10 ΔY= 8P0=2ΔY –Δx=6 2ΔY =16 2(ΔY – ΔX)=-4
P0=2ΔY –ΔXPk+1 = Pk + 2ΔY or = Pk + 2(ΔY – ΔX(
![Page 22: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/22.jpg)
22
Line Drawing Algorithms : Bresenham’s algorithm example
![Page 23: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/23.jpg)
23
Problem of Clipping
•Bad idea to rasterize outside of framebuffer bounds •Also, don’t waste time scan converting pixels outside window
![Page 24: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/24.jpg)
24
Clipping: The Real World
•The Sutherland-Hodgeman algorithm (clipping polygons to a region one plane at a time) generalizes to 3-D•The problem: clipping a line segment to an arbitrary plane is relatively expensive
Projectionmatrix;homogeneousdivide
Clip in 2-D screen coordinates
Clip against
hither andyon planes
Transform intoscreen coordinates
![Page 25: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/25.jpg)
25
Circle algorithm
![Page 26: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/26.jpg)
26
Circle Algorithms
•Polar formx = rCosy = rSin (r = radius of circle)
P=(rCos, rSin)
rSin)
rCos)x
y
r
![Page 27: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/27.jpg)
27
Circle Algorithms : Drawing a circle
•The equation of a circle
We could solve for y in terms of x
![Page 28: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/28.jpg)
28
Circle Generating Algorithms
The spacing between plotted pixel positions is not uniform.
![Page 29: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/29.jpg)
29
Circle Generating Algorithms
• Computation can be reduced by considering the symmetry of circles
![Page 30: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/30.jpg)
30
Midpoint circle Algorithms
• As in the line algorithm, we sample at unit intervals and determine the closet pixel position to the circle path at each step.
![Page 31: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/31.jpg)
31
Midpoint circle Algorithms
• Points are generated from 90º to 45º, moves will be made only in the +x and –y direction.
• positive x direction over this octant and use a decision parameter
![Page 32: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/32.jpg)
32
Midpoint circle Algorithms
• We define a circle function:
o
ryxyxfcircle 0
0
),( 222
![Page 33: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/33.jpg)
33
Midpoint circle Algorithms
• Midpoint
• Consider the coordinates of the point halfway between pixel T and pixel S
)21
,1( ii
yx
Midpoint
![Page 34: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/34.jpg)
34
Midpoint circle Algorithms
![Page 35: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/35.jpg)
35
Example
•r = 10
•p0 = 1 – r = -9 (if r is integer round p0 = 5/4 – r to integer)
•Initial point (x0, y0) = (0, 10)
i pi xi+1, yi+1 2xi+1 2yi+1
0 -9 (1, 10) 2 20
1 -6 (2, 10) 4 20
2 -1 (3, 10) 6 20
3 6 (4, 9) 8 18
4 -3 (5, 9) 10 18
5 8 (6, 8) 12 16
6 5 (7, 7)
10 9
8 7 6
5 4 3
2 1 0
0 1 2 3 4 5 6 7 8 9 10
![Page 36: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/36.jpg)
36
Bresenham’s Circle Algorithm
General PrincipleGeneral Principle•The circle function:
and
2 2 2( , )circlef x y x y r
if (x,y) is inside the circle boundary
if (x,y) is on the circle boundary
if (x,y) is outside the circle boundary
0
( , ) 0
0circlef x y
Consider only 45° ≤ ≤ 90
![Page 37: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/37.jpg)
37 37
Bresenham’s Circle Algorithm
p1 p3
p2
D(si)D(ti)
yi
yi - 1
xi xi + 1
r
![Page 38: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/38.jpg)
38
Bresenham’s Circle Algorithm
Define: D(si) = distance of p3 from circle
D(ti) = distance of p2 from circle
i.e. D(si) = (xi + 1)2 + yi2 – r2 [always +ve]
D(ti) = (xi + 1)2 + (yi – 1)2 – r2 [always -ve]
•Decision Parameter pi = D(si) + D(ti)
so if pi < 0 then the circle is closer to p3 (point above) if pi ≥ 0 then the circle is closer to p2 (point below)
![Page 39: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/39.jpg)
39
Bresenham’s Circle Algorithm
x0 = 0y0 = rp0 = [12 + r2 – r2] + [12 + (r-1)2 – r2] = 3 – 2r
if pi < 0 thenyi+1 = yi
pi+1 = pi + 4xi + 6
else if pi ≥ 0 thenyi+1 = yi – 1pi+1 = pi + 4(xi – yi) + 10
•Stop when xi ≥ yi and determine symmetry points in the other octants
xi+1 = xi + 1
![Page 40: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/40.jpg)
40
Bresenham’s Circle Algorithm : Example
10 9 8 7 6
5 4 3
2 1 0
0 1 2 3 4 5 6 7 8 9 10
i pi xi, yi
0 -17 (0, 10)
1 -11 (1, 10)
2 -1 (2, 10)
3 13 (3, 10)
4 -5 (4, 9)
5 15 (5, 9)
6 9 (6, 8)
7 (7,7)
r = 10
p0 = 3 – 2r = -17
Initial point (x0, y0) = (0, 10)
![Page 41: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/41.jpg)
41
Advantages of Bresenham circle
•Only involves integer addition, subtraction and multiplication•There is no need for squares, square roots and trigonometric functions
![Page 42: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/42.jpg)
42
Ellipse algorithm
![Page 43: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/43.jpg)
43
Ellipse Algorithm
)cos(xc rxx
)sin(yc ryy
![Page 44: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/44.jpg)
44
Ellipse Algorithm
![Page 45: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/45.jpg)
45
Example: Midpoint Ellipse Algorithm
![Page 46: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/46.jpg)
46
Example: Midpoint Ellipse Algorithm
![Page 47: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/47.jpg)
47
Pixel addressing
![Page 48: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/48.jpg)
Setting frame-buffer values
• After generating a line or circle using scan conversion, we need to know where is the specified pixels are stored in the frame buffer.
• Frame buffer is stored in memory as an addressable array and stored row by row.
• Pixels are labeled from (0, 0) the lower left corner to (xmax,ymax) the top right corner.
48
![Page 49: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/49.jpg)
Row by Row mapping
49
![Page 50: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/50.jpg)
Setting frame-buffer values (cont.)
• For a bilevel system (1 bit per pixel),the Frame-Buffer bit address for pixel position (x, y) is calculated as:
1. addr(x, y) = addr (0,0) + y (xmax +1) + x
2. addr(x + 1, y) = addr(x, y) + 1
3. addr(x + 1, y + 1) = addr(x, y) + xmax + 2
50
![Page 51: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/51.jpg)
Setting frame-buffer values (cont.)
• Example:Find the address of the pixel (6,5), where the address of (0,0) =500, xmax=12, and ymax = 10.
addr(x, y) = addr (0,0) + y(xmax +1) + x
addr(6, 5) = 500 + 5(12 + 1) + 6 = 571
addr(7, 5) = addr(6, 5) + 1 = 572addr(7, 6) = addr(6, 5) + xmax + 2 = 585
51
![Page 52: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/52.jpg)
Pixel addressing and object geometry
• When an object is scan converted into the frame buffer, the input description is transformed to pixel coordinates.
• So, the displayed image may not correspond exactly with the relative dimensions of the input object.
• To preserve the specified geometry of world objects, we need to compensate for the mapping of mathematical input points to finite pixel area, we use one of the two ways:
52
![Page 53: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/53.jpg)
Pixel addressing and object geometry (cont.)
1) Adjust the dimensions of displayed objects to account for the amount of overlap of pixel areas with the object boundaries.
(i.e. a rectangle with 40 cm width, will be displayed in 40 pixel)
2) Map world coordinates onto screen positions between pixels, so that we align objects boundaries with pixel boundaries instead of pixel centers.
53
![Page 54: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/54.jpg)
Pixel addressing and object geometry (cont.)
Screen Grid Coordinates:
An alternative to addressing display positions in terms of pixel centers is to reference screen coordinates with respect to the grid of horizontal and vertical pixel boundary lines spaced one unit a part.
![Page 55: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/55.jpg)
Pixel addressing and object geometry (cont.)
• Screen coordinate position is then the pair of integer values identifying a grid intersection position between two pixels.
• For example, the mathematical line path for a polyline with screen endpoints (0, 0), (5, 2), and (1,4) is shown beside.
![Page 56: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/56.jpg)
Pixel addressing and object geometry (cont.)
• With the coordinate origin at the lower left of the screen, each pixel area can be referenced by the integer grid coordinates of its lower left corner.
• The following figure illustrates this convention for an 8 by 8 section of a raster, with a single illuminated pixel at screen coordinate position (4, 5).
![Page 57: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/57.jpg)
Pixel addressing and object geometry (cont.)
• In general, we identify the area occupied by a pixel with screen coordinates ( x, y) as the unit square with diagonally opposite corners at (x, y) and ( x + 1, y + 1 ).
• This pixel addressing scheme has several advantages:1. It avoids half-integer pixel boundary2. It facilitates precise object representations.3. Simplifies the processing involved in many scan conversion
algorithms and in other raster procedures
57
![Page 58: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/58.jpg)
Pixel addressing and object geometry (cont.)
Notes:
1) The previous algorithms for drawing line, circle, …etc are still valid when applied to input positions expressed as screen grid coordinates.
2) The decision parameter Pk is a measure of screen grid separation differences rather than separation differences from pixel centers.
58
![Page 59: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/59.jpg)
Pixel addressing and object geometry (cont.)
A circle of radius 5 and center position (10, 10), for instance, would be displayed by the midpoint circle algorithm using screen grid coordinate positions.
But the plotted circle has a diameter of 11, To plot the circle with the defined diameter of 10, we can modify the circle algorithm to shorten each pixel scan line and each pixel column.
59
![Page 60: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/60.jpg)
Pixel addressing and object geometry (cont.)
60
![Page 61: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/61.jpg)
Pixel addressing and object geometry (cont.)
61
![Page 62: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/62.jpg)
62
Area Fill Methods
![Page 63: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/63.jpg)
Point and Line primitives
GL_POINTS: sequence of points
GL_LINES: sequence of line segments
GL_LINE_STRIP: polyline
GL_LINE_LOOP: closed polyline
12
34
1
2
3
4 5
6 7
8
1
2
3
4
5
1
23
4
5
![Page 64: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/64.jpg)
Area fill primitives 1
• Point, line and curve, fill area• Usually polygons• 2D shapes and boundary 3D objects
![Page 65: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/65.jpg)
Area fill primitives 2
• Approximation of curved surface:– Surface mesh or Surface tesselation– Face or facet (planar), patch (curved)
![Page 66: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/66.jpg)
Polygon
• Polygon: – Planar shape, defined by a sequence of three or more vertices,
connected by line segments (edges or sides)– Standard or simple polygon: no crossing edges
bowtie polygon
![Page 67: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/67.jpg)
Regular polygon
• Vertices uniformly distributed over a circle:
NiNirNiryx ii ...1)),/2sin(),/2cos((),( PP
r
![Page 68: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/68.jpg)
Convex vs. concave 1
• Convex: – All interior angles < 180 graden, 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
![Page 69: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/69.jpg)
Convex vs. concave 2
• Puzzle:
Given a planar polygon in 3D, with vertices Pi, with i = 1, … , N.
Give a recipe to determine if the polygon is convex or concave.
![Page 70: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/70.jpg)
Convex vs. concave 3
• Puzzle:
Given a planar polygon in 3D, with vertices Pi, with i = 1, … , N.
Give a recipe to determine if the polygon is convex or concave.
Solution: (multiple solutions possible)
. that here Assume concave. else
convex, then ,
with,,...,1 allfor 0 If
iNi
i1i1iii
i1i
PP
)P(P)P(PQ
Ni
![Page 71: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/71.jpg)
Splitting concave polygons
.en through line thealongpolygon Split the
concave. is angle Suppose, concave.or convex
iscorner if determine and verticesalongWalk
i1i
1ii1i
PP
PPP
iP
1iP
1iP
![Page 72: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/72.jpg)
Convex polygon triangles
Repeat Pick three succeeding points; Join the outside ones with a line; Remove the middle pointUntil three points are left over
![Page 73: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/73.jpg)
OpenGL Area Fill
glBegin(GL_POLYGON); // Specify what to draw, // a polygon
// Geometric info via vertices: glVertex*(); // 1 glVertex*(); // 2 ... // ...glEnd;
glVertex[234][isfd]
[234]: 2D, 3D, 4D[isfd]: integer, short, float, doubleFor instance: glVertex2i(100, 25);
![Page 74: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/74.jpg)
OpenGL Area Fill
GL_POLYGON: convex polygon
Concave polygons give unpredictable results.
1
2
34
5
1
3
45
![Page 75: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/75.jpg)
OpenGL Area Fill
• GL_TRIANGLES: sequence of triangles
• GL_TRIANGLE_STRIP:
• GL_TRIANGLE_FAN:
1
2
3
4
56
7
8
9
1
2
3
4
5
6
7
8
1
23
4
5
6
![Page 76: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/76.jpg)
OpenGL Area Fill
• GL_QUADS: sequence of quadrilaterals
• GL_QUAD_STRIP: strip of quadrilaterals
1
2
34
5 6
78
9
1011
12
1
2
3
4
5
6
7
8
![Page 77: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/77.jpg)
OpenGL output functions
glBegin(GL_LINES); // Specify what to draw, // here lines// Geometric info via vertices: glVertex*(); // 1 glVertex*(); // 2 ... // ...glEnd;glVertex[234][isfd][234]: 2D, 3D, 4D[isfd]: integer, short, float, doubleFor instance: glVertex2i(100, 25);
![Page 78: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/78.jpg)
Vertex Array
• OpenGL provides a facility called vertex arrays that allows us to store array data in the implementation
• Six types of arrays supported– Vertices– Colors– Color indices– Normals– Texture coordinates– Edge flags
• We will need only colors and vertices
![Page 79: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/79.jpg)
79
Character Handling
•Letters, numbers, and other character can be displayed in a variety of size and styles.
•Typeface: The overall design style for a set of characters is call typeface: Zar, nazanin, Titr.
•Font: Referred to a set of cast metal character forms in a particular size and forma: 10 point Zar.
•Two different representation are used for storing computer fonts:– Bitmap font (or bitmapped font)
– Outline font
![Page 80: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/80.jpg)
80
Bitmap Handling
• Bitmap font (or bitmapped font): A simple method for representing the character shapes in a particular typeface is to use rectangular grid pattern.
![Page 81: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/81.jpg)
81
• The character grid only need to be mapped to a frame buffer position.
• Bitmap fonts required more space, because each variation (size and format) must be stored in a font cash.
Bold Italic
![Page 82: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/82.jpg)
82
Outline Font
• Graphic primitives such as lines and arcs are used to define the outline of each character.
• Require less storage since variation does not require a distinct font cash.
• We can produce boldface, italic, or different size by manipulating the curve definition for the character outlines.
• It does take more time to process the outline fonts, because they must be scan converted into frame buffer.
![Page 83: 1 EEL 5771-001 Introduction to Computer Graphics PPT2: Graphics Output Primitives By Arunbalaji Prithiviraj (U80066848)](https://reader036.vdocuments.site/reader036/viewer/2022062517/56649ec65503460f94bd1e6a/html5/thumbnails/83.jpg)
83
References
• Hughes, John F., et al. Computer graphics: principles and practice. Pearson Education, 2013.
• Van Dam, Andries, et al. Introduction to computer graphics. Vol. 55. Reading: Addison-Wesley, 1994.
• Hearn, Donald, and M. Pauline Baker. "Computer Graphics with Open GL, 3/E."ISBN: 0-13-015390-7, Prentice Hall (2004).
• Van Aken, Jerry R. "An efficient ellipse-drawing algorithm." Computer Graphics and Applications, IEEE 4.9 (1984): 24-35.
• Wright, William E. "Parallelization of Bresenham's line and circle algorithms."Computer Graphics and Applications, IEEE 10.5 (1990): 60-67.