Graphics Primitives in OpenGL
Graphics Primitives in OpenGL
Drawing Primitives
Line Drawing
Polygon Drawing
Point Drawing in
OpenGL
Line Drawing
Algorithms
Circle Drawing
Algorithms
Fill-Area Primitives
OpenGL Drawing Primitives
4
Point Drawing in
OpenGL Are represented by the two end-points
Point Drawing in
OpenGL
Line Drawing
Algorithms
Circle Drawing
Algorithms
Fill-Area Primitives
y end y 0 c y mx
m 0 0
x end x0
8
2. Line Drawing algorithms
Point Drawing in
OpenGL For any given x-interval δx, we can
Line Drawing δy = m
DDA Algorithm δy = 1
Paint (x0,y0)
Find successive pixel positions
Bresenham’s
xk+1 = (xk + δx)
Algorithm
yk+1 = (yk + δy)
Fill-Area Primitives
10
Digital Differential Analyzer Algorithm
Example
Given (x0,y0) = (10,10) yend y0 (13 10) 3
Point Drawing in m 0.6
and (xend,yend) = (15,13)
OpenGL xend x0 (15 10) 5
Compute m
Line Drawing If |m| ≤ 1:
Algorithms δx = 1
δx = 1
δy = m δy = 0.6
If |m| > 1:
DDA Algorithm
δx = 1/m
δy = 1
Bresenham’s Paint (x0,y0) (xend,yend) = (15,13)
Algorithm
Circle Drawing
Algorithms
δy = 1
Bresenham’s Paint (x0,y0) (xend,yend) = (15,13)
Algorithm
Circle Drawing
Algorithms
Circle Drawing
Algorithms
Circle Drawing
Algorithms
Circle Drawing
Algorithms
Circle Drawing
Algorithms
Circle Drawing
Algorithms
|m| < 1
Point Drawing in
OpenGL Plot (x0,y0)
Compute the first
Line Drawing decision variable:
Algorithms p0 2y x
For each k, starting with
DDA Algorithm k=0:
If pk < 0:
DDA Algorithm
Circle Drawing
Algorithms
Circle Drawing
Algorithms
Circle Drawing
Algorithms
Fill-Area Primitives
27
Bresenham’s vs. DDA…
Fill-Area Primitives
28
Point Drawing in
OpenGL We can draw straight-lines in OpenGL
Fill-Area Primitives
(GL_LINE_LOOP)
Questions
30
31
Circle Drawing Algorithms
Circle
Point Drawing in
OpenGL
Line Drawing
Algorithms
Circle Drawing
Algorithms
Basic Algorithms
Midpoint
Algorithms
Fill-Area Primitives
32
Circle Drawing Algorithms
1. Plotting Points Using Cartesian Coordinates
Point Drawing in Incrimenting x and computing y
OpenGL
2
y yc r 2 xc x
Line Drawing
Algorithms
Line Drawing
Algorithms
Circle Drawing
Algorithms
Basic Algorithms
Midpoint
Algorithms o A need of another int based algorithm
Fill-Area Primitives
36
Midpoint Algorithm
Given the center and r
Point Drawing in Plot the start-point of the
OpenGL circle (x0,y0) = (xc,r)
Compute the first decision
Line Drawing variable:
Algorithms p0 1 r
For each k, starting with
Circle Drawing k=0:
Algorithms If pk < 0:
Plot (xk+1,yk)
Basic Algorithms pk 1 pk 2xk 1 1
Otherwise:
Midpoint Plot (xk+1,yk-1)
Algorithms
pk1 pk 2xk1 1 2yk1
Fill-Area Primitives
37
Midpoint Algorithm Example
Given the center (0,0) and r = 10
Plot the start-point of the circle (x0,y0) = (xc,r) = (0,10)
Point Drawing in
Compute the first decision variable:
OpenGL
p0 1 r
Line Drawing
Algorithms (10,10)
Circle Drawing P = -9
Algorithms
Basic Algorithms
Midpoint
Algorithms
Fill-Area Primitives
(0,0)
38
Midpoint Algorithm Example
p0 < 0,
Point Drawing in Plot (x1,y1) = (x0+1,y0) = (1,10)
OpenGL
p1 p0 2x1 1 9 3 6
Line Drawing
Algorithms (10,10)
Circle Drawing p0 = -9
Algorithms
Basic Algorithms
Midpoint
Algorithms
Fill-Area Primitives
(0,0)
39
Midpoint Algorithm Example
p1 < 0,
Plot (x2,y2) = (x1+1,y1) = (2,10)
Point Drawing in
OpenGL p2 p1 2x2 1 6 5 1
Line Drawing
Algorithms (10,10)
Circle Drawing p1 = -6
Algorithms
Basic Algorithms
Midpoint
Algorithms
Fill-Area Primitives
(0,0)
40
Midpoint Algorithm Example
p2 < 0,
Plot (x3,y3) = (x2+1,y2) = (3,10)
Point Drawing in
OpenGL p3 p2 2x3 1 1 7 6
Line Drawing
Algorithms (10,10)
Circle Drawing p2 = -1
Algorithms
Basic Algorithms
Midpoint
Algorithms
Fill-Area Primitives
(0,0)
41
Midpoint Algorithm Example
p3 ≥ 0
Plot (x4,y4) = (x3+1,y3-1) = (4,9)
Point Drawing in
OpenGL p4 p3 2x4 12y4 69 3
Line Drawing
Algorithms (10,10)
Circle Drawing p3 = 6
Algorithms
Basic Algorithms
Midpoint
Algorithms
Fill-Area Primitives
(0,0)
42
Midpoint Algorithm Example
p4 < 0,
Plot (x5,y5) = (x4+1,y4) = (5,9)
Point Drawing in
OpenGL p 5 p 4 2 x 5 1 3 11 8
Line Drawing
Algorithms (10,10)
Circle Drawing p4 = -3
Algorithms
Basic Algorithms
Midpoint
Algorithms
Fill-Area Primitives
(0,0)
43
Midpoint Algorithm Example
p5 ≥ 0,
Plot (x6,y6) = (x5+1,y5-1) = (6,8)
Point Drawing in
OpenGL p6 p5 2x6 12y6 83 5
Line Drawing
Algorithms (10,10)
Circle Drawing p5 = 8
Algorithms
Basic Algorithms
Midpoint
Algorithms
Fill-Area Primitives
(0,0)
44
Midpoint Algorithm Example
p6 ≥ 0,
Plot (x7,y7) = (x6+1,y6-1) = (7,7)
Point Drawing in
OpenGL p7 p6 2x7 12y7 19136
Line Drawing
Algorithms (10,10)
Circle Drawing p6 = 5
Algorithms
Basic Algorithms
Midpoint
Algorithms
Fill-Area Primitives
(0,0)
45
Midpoint Algorithm Example
p7 ≥ 0,
Plot (x8,y8) = (x7+1,y7-1) = (8,6)
Point Drawing in
OpenGL p8 p7 2x8 12y8 221111
Line Drawing
Algorithms (10,10)
Circle Drawing p7 = 6
Algorithms
Basic Algorithms
Midpoint
Algorithms
Fill-Area Primitives
(0,0)
46
Midpoint Algorithm Example
p8 ≥ 0,
Plot (x9,y9) = (x8+1,y8-1) = (9,5)
Point Drawing in
OpenGL
Line Drawing
Algorithms (10,10)
Circle Drawing p8 = 11
Algorithms
Basic Algorithms
Midpoint
Algorithms
Fill-Area Primitives
(0,0)
Any Question?
47