Professional Documents
Culture Documents
UNIT I Computer Graphics
UNIT I Computer Graphics
7
Rendering ??
• Geometric primitives
• Points
• lines or polygons
• Image Primitives
• images and bitmaps
• separate pipeline for images and geometry
• linked through texture mapping
8
OpenGL Architecture
Per Vertex
Polynomial Operations &
Evaluator Primitive
Assembly
Texture
Memory
Pixel
Operations
9
OpenGL as a Renderer
• Geometric primitives
• points, lines and polygons
• Image Primitives
• images and bitmaps
• separate pipeline for images and geometry
• linked through texture mapping
• Rendering depends on state
• colors, materials, light sources, etc.
10
OpenGL and Related APIs
application program
11
GLUT Basics
• Application Structure
• Configure and open window
• Initialize OpenGL state
• Register input callback functions
• render
• resize
• input: keyboard, mouse, etc.
• Enter event processing loop
12
OpenGL Geometric Primitives
• All geometric primitives are specified by vertices
GL_LINES
GL_POINTS GL_POLYGON
GL_LINE_STRIP GL_LINE_LOOP
GL_TRIANGLES
GL_TRIANGLE_STRIP GL_QUADS GL_QUAD_STRIP
GL_TRIANGLE_FAN
13
RGBA versus Color-Index Mode
Shapes Tutorial
15
Digital Differential Analyzer
Line Drawing Algorithm
DDA Algorithm
• The digital differential analyzer (DDA) is line drawing
algorithm based on calculating either δy or δx.
• A line is sampled at unit intervals in one coordinate and the
corresponding integer values nearest the line path are
determined for the other coordinate.
DDA Algorithm…
BRESENHAM’S
LINE
DRAWING
ALGORITHM
INTRODUCTION
• It can be used to make decision about which pixel is closer to the line
• This decision is based on the difference between the two pixel positions,
𝑑 − 𝑑 = 2𝑚 𝑥 + 1
− 2𝑦𝑘+ 2𝑏 − 1
𝑢𝑝𝑝𝑒𝑟 𝑜𝑙𝑤𝑒𝑟 𝑘
• By substituting 𝑚 = ∆𝑦/∆𝑥 and both are differences of end points,
∆𝑦
∆𝑥 𝑑𝑢𝑝𝑝𝑒𝑟− 𝑑𝑜𝑙𝑤𝑒𝑟
= ∆𝑥 2 𝑥𝑘 + 1 − 2𝑦𝑘+ 2𝑏 − 1
∆𝑥
= 2∆𝑦. 𝑥𝑘 − 2∆𝑥. 𝑦𝑘 + 2∆𝑦 + ∆𝑥(2𝑏 − 1)
= 2∆𝑦. 𝑥𝑘 − 2∆𝑥. 𝑦𝑘 + 𝐶
DERIVATION
• 𝑥𝑘+1 is same as 𝑥𝑘 + 1 so,
𝑃𝑘+1 = 𝑃𝑘+ 2∆𝑦 − 2∆𝑥(𝑦𝑘+1 − 𝑦𝑘)
• Here, 𝑦𝑘+1− 𝑦𝑘 is either 0 or 1 depending on the sign of 𝑃𝑘
• If 𝑃𝑘 < 0, the next point to plot is (𝑥𝑘+ 1, 𝑦𝑘) and new value of 𝑃is,
𝑃𝑘+1 = 𝑃𝑘+ 2∆𝑦
• If 𝑃𝑘 > 0, the next point to plot is (𝑥𝑘+ 1, 𝑦𝑘 + 1) and new value of 𝑃 is,
𝑃𝑘+1 = 𝑃𝑘 + 2∆𝑦 − 2∆𝑥
• The first decision parameter 𝑃0is evaluated at (𝑥0, 𝑦0) is,
𝑃0= 2∆𝑦 − ∆𝑥
Bresenham
Circle Drawing Algorithm,
(xk +1, yk)
FIRST
(xk+1, yk–1)
•For a pixel at (xk, kOCTANT
y ) the next pixel (x +1, y ) or at (x +1, y –1) is
k k k k
closer to the circle.
•The pixel point Pk for a corresponding point on the circle is given as:
Pk = f(xk + 1, yk – ½) = (xk + 1)2 + (yk - ½)2 – r2
equation, P0 = f(1, r – ½) = 𝟓 𝟒 - r
(0, 0)
Since r is a integer, neglecting the small
value of ¼, we have P0 = 1 - r
BRESSENHAM’S
ALGORITHM
1. Input radius r and centre of the circle (xc, yc), and obtain the first
point on the circumference of a circle centred on the origin as
(x0, y0) = (0, r)
If (Pk < 0), then the NEXT POINT along the circle centred on (0, 0) is
(xk+1, yk) and Pk+1 = Pk + 2xk+1 +1
Pk+1 = Pk + 2xk + 3
2xk+1 = 2xk + 2
Otherwise, the NEXT POINT along the circle is (xk+1, yk–1) and Pk+1 = Pk +
2xk+1 + 1 – 2yk+1
Pk+1 = Pk + 2xk – 2yk + 5
2yk+1 = 2yk – 2
4. Determine the Symmetry Points on the other 7 Octants
x = x + xc and y = y + yc
(-x, y) (x, y)
(-y, x) (y, x)
R
2
(-y, -x) (y, -x)
p0 5 r
4
• Perform the test, Starting with k = 0 at each position xk,
perform the following test.
• (i) If pk < 0, the next point along the circle centred on (0, 0)
is (xk+1, yk) and: p p 2x 1
k 1 k k 1
The Mid-Point Circle Algorithm (cont…)
• (ii) If Pk >0 then the next point along the circle is (xk+1,
yk-1) and:
pk 1 pk 2 xk 1 1 2 yk 1
• 2 xk 1 = 2Xk+2 and 2 yk 1= 2Yk – 2
where
• Identify the symmetry points in the other seven octants
• Move (x, y) according to:
x x xc y y yc
• Repeat steps 3 to 5 until x >= y