SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Downloaden Sie, um offline zu lesen
CS 4731: Computer Graphics
Lecture 18: Raster Graphics Part 1
Emmanuel Agu
2D Graphics Pipeline
Object
World Coordinates
Object
subset
window to
viewport
mapping
Object
Screen coordinates
RasterizationDisplay
Applying
world window
Clipping
Simple 2D Drawing Pipeline
Rasterization (Scan Conversion)
n Convert high-level geometry description to pixel colors
in the frame buffer
n Example: given vertex x,y coordinates determine pixel
colors to draw line
n Two ways to create an image:
n Scan existing photograph
n Procedurally compute values (rendering)
Viewport
Transformation
Rasterization
Rasterization
n A fundamental computer graphics function
n Determine the pixels’ colors, illuminations, textures, etc.
n Implemented by graphics hardware
n Rasterization algorithms
n Lines
n Circles
n Triangles
n Polygons
Rasterization Operations
n Drawing lines on the screen
n Manipulating pixel maps (pixmaps): copying, scaling,
rotating, etc
n Compositing images, defining and modifying regions
n Drawing and filling polygons
n Previously glBegin(GL_POLYGON), etc
n Aliasing and antialiasing methods
Line drawing algorithm
n Programmer specifies (x,y) values of end pixels
n Need algorithm to figure out which intermediate pixels
are on line path
n Pixel (x,y) values constrained to integer values
n Actual computed intermediate line values may be floats
n Rounding may be required. E.g. computed point
(10.48, 20.51) rounded to (10, 21)
n Rounded pixel value is off actual line path (jaggy!!)
n Sloped lines end up having jaggies
n Vertical, horizontal lines, no jaggies
Line Drawing Algorithm
0 1 2 3 4 5 6 7 8 9 10 11 12
8
7
6
5
4
3
2
1
Line: (3,2) -> (9,6)
? Which intermediate
pixels to turn on?
Line Drawing Algorithm
n Slope-intercept line equation
n y = mx + b
n Given two end points (x0,y0), (x1, y1), how to compute m
and b?
(x0,y0)
(x1,y1)
dx
dy
01
01
xx
yy
dx
dy
m
−
−
== 0*0 xmyb −=
Line Drawing Algorithm
n Numerical example of finding slope m:
n (Ax, Ay) = (23, 41), (Bx, By) = (125, 96)
5392.0
102
55
23125
4196
==
−
−
=
−
−
=
AxBx
AyBy
m
Digital Differential Analyzer (DDA): Line Drawing
Algorithm
(x0,y0)
(x1,y1)
dx
dy
§Walk through the line, starting at (x0,y0)
§Constrain x, y increments to values in [0,1] range
§Case a: x is incrementing faster (m < 1)
§Step in x=1 increments, compute and round y
§Case b: y is incrementing faster (m > 1)
§Step in y=1 increments, compute and round x
m<1
m>1
m=1
DDA Line Drawing Algorithm (Case a: m < 1)
(x0, y0)
x = x0 + 1 y = y0 + 1 * m
Illuminate pixel (x, round(y))
x = x + 1 y = y + 1 * m
Illuminate pixel (x, round(y))
…
Until x == x1
(x1,y1)
x = x0 y = y0
Illuminate pixel (x, round(y))
myy kk +=+1
DDA Line Drawing Algorithm (Case b: m > 1)
y = y0 + 1 x = x0 + 1 * 1/m
Illuminate pixel (round(x), y)
y = y + 1 x = x + 1 /m
Illuminate pixel (round(x), y)
…
Until y == y1
x = x0 y = y0
Illuminate pixel (round(x), y)
(x1,y1)
(x0,y0)
m
xx kk
1
1 +=+
DDA Line Drawing Algorithm Pseudocode
compute m;
if m < 1:
{
float y = y0; // initial value
for(int x = x0;x <= x1; x++, y += m)
setPixel(x, round(y));
}
else // m > 1
{
float x = x0; // initial value
for(int y = y0;y <= y1; y++, x += 1/m)
setPixel(round(x), y);
}
n Note: setPixel(x, y) writes current color into pixel in column x and
row y in frame buffer
Line Drawing Algorithm Drawbacks
n DDA is the simplest line drawing algorithm
n Not very efficient
n Round operation is expensive
n Optimized algorithms typically used.
n Integer DDA
n E.g.Bresenham algorithm (Hill, 10.4.1)
n Bresenham algorithm
n Incremental algorithm: current value uses previous value
n Integers only: avoid floating point arithmetic
n Several versions of algorithm: we’ll describe midpoint
version of algorithm
Bresenham’s Line-Drawing Algorithm
n Problem: Given endpoints (Ax, Ay) and (Bx, By) of a line,
want to determine best sequence of intervening pixels
n First make two simplifying assumptions (remove later):
n (Ax < Bx) and
n (0 < m < 1)
n Define
n Width W = Bx – Ax
n Height H = By - Ay
(Bx,By)
(Ax,Ay)
Bresenham’s Line-Drawing Algorithm
n Based on assumptions:
n W, H are +ve
n H < W
n As x steps in +1 increments, y incr/decr by <= +/–1
n y value sometimes stays same, sometimes increases by 1
n Midpoint algorithm determines which happens
Bresenham’s Line-Drawing Algorithm
(x0, y0)
M = (x0 + 1, Y0 + ½)
Build equation of line through and compare
to midpoint
…
(x1,y1)
What Pixels to turn on or off?
Consider pixel midpoint M(Mx, My)
M(Mx,My)
If midpoint is above line, y stays same
If midpoint is below line, y increases + 1
Bresenham’s Line-Drawing Algorithm
n Using similar triangles:
n H(x – Ax) = W(y – Ay)
n -W(y – Ay) + H(x – Ax) = 0
n Above is ideal equation of line through (Ax, Ay) and (Bx, By)
n Thus, any point (x,y) that lies on ideal line makes eqn = 0
n Double expression (to avoid floats later), and give it a name,
F(x,y) = -2W(y – Ay) + 2H(x – Ax)
W
H
Axx
Ayy
=
−
−
(Bx,By)
(Ax,Ay)
(x,y)
Bresenham’s Line-Drawing Algorithm
n So, F(x,y) = -2W(y – Ay) + 2H(x – Ax)
n Algorithm, If:
n F(x, y) < 0, (x, y) above line
n F(x, y) > 0, (x, y) below line
n Hint: F(x, y) = 0 is on line
n Increase y keeping x constant, F(x, y) becomes more
negative
Bresenham’s Line-Drawing Algorithm
n Example: to find line segment between (3, 7) and (9, 11)
F(x,y) = -2W(y – Ay) + 2H(x – Ax)
= (-12)(y – 7) + (8)(x – 3)
n For points on line. E.g. (7, 29/3), F(x, y) = 0
n A = (4, 4) lies below line since F = 44
n B = (5, 9) lies above line since F = -8
Bresenham’s Line-Drawing Algorithm
(x0, y0)
M = (x0 + 1, Y0 + ½)
If F(Mx,My) < 0, M lies above line,
shade lower pixel (same y as before)
…
(x1,y1)
What Pixels to turn on or off?
Consider pixel midpoint M(Mx, My)
M(Mx,My)
If F(Mx,My) > 0, M lies below line,
shade upper pixel
Can compute F(x,y) incrementally
Initially, midpoint M = (Ax + 1, Ay + ½)
F(Mx, My) = -2W(y – Ay) + 2H(x – Ax)
= 2H – W
Can compute F(x,y) for next midpoint incrementally
If we increment x + 1, y stays same, compute new F(Mx,My)
F(Mx, My) += 2H
If we increment x +1, y + 1
F(Mx, My) -= 2(W – H)
Bresenham’s Line-Drawing Algorithm
Bresenham(IntPoint a, InPoint b)
{ // restriction: a.x < b.x and 0 < H/W < 1
int y = a.y, W = b.x – a.x, H = b.y – a.y;
int F = 2 * H – W; // current error term
for(int x = a.x; x <= b.x; x++)
{
setpixel at (x, y); // to desired color value
if F < 0
F = F + 2H;
else{
Y++, F = F + 2(H – W)
}
}
}
n Recall: F is equation of line
Bresenham’s Line-Drawing Algorithm
n Final words: we developed algorithm with restrictions
0 < m < 1 and Ax < Bx
n Can add code to remove restrictions
n To get the same line when Ax > Bx (swap and draw)
n Lines having m > 1 (interchange x with y)
n Lines with m < 0 (step x++, decrement y not incr)
n Horizontal and vertical lines (pretest a.x = b.x and skip tests)
n Important: Read Hill 10.4.1
References
n Hill, chapter 10

Weitere ähnliche Inhalte

Was ist angesagt?

Dda line algorithm presentatiion
Dda line algorithm presentatiionDda line algorithm presentatiion
Dda line algorithm presentatiionMuhammadHamza401
 
Bresenhamcircle derivation
Bresenhamcircle derivationBresenhamcircle derivation
Bresenhamcircle derivationMazharul Islam
 
Computer graphics presentation
Computer graphics presentationComputer graphics presentation
Computer graphics presentationLOKENDRA PRAJAPATI
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmKasun Ranga Wijeweera
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsKetan Jani
 
Computer graphics - bresenham line drawing algorithm
Computer graphics - bresenham line drawing algorithmComputer graphics - bresenham line drawing algorithm
Computer graphics - bresenham line drawing algorithmRuchi Maurya
 
Intro to scan conversion
Intro to scan conversionIntro to scan conversion
Intro to scan conversionMohd Arif
 
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSEAU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSEThiyagarajan G
 
Unit 2
Unit 2Unit 2
Unit 2ypnrao
 
Output primitives computer graphics c version
Output primitives   computer graphics c versionOutput primitives   computer graphics c version
Output primitives computer graphics c versionMarwa Al-Rikaby
 
DDA (digital differential analyzer)
DDA (digital differential analyzer)DDA (digital differential analyzer)
DDA (digital differential analyzer)Inamul Hossain Imran
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterizationMaaz Rizwan
 
Apoyo guía-12-2°-medio-ppt.-parábola
Apoyo guía-12-2°-medio-ppt.-parábolaApoyo guía-12-2°-medio-ppt.-parábola
Apoyo guía-12-2°-medio-ppt.-parábolaliceo
 
CST 504 Distance in the Cartesian Plane
CST 504 Distance in the Cartesian PlaneCST 504 Distance in the Cartesian Plane
CST 504 Distance in the Cartesian PlaneNeil MacIntosh
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesOmprakash Chauhan
 

Was ist angesagt? (20)

Dda algo notes
Dda algo notesDda algo notes
Dda algo notes
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Dda line algorithm presentatiion
Dda line algorithm presentatiionDda line algorithm presentatiion
Dda line algorithm presentatiion
 
Lect3cg2011
Lect3cg2011Lect3cg2011
Lect3cg2011
 
Bresenhamcircle derivation
Bresenhamcircle derivationBresenhamcircle derivation
Bresenhamcircle derivation
 
Computer graphics presentation
Computer graphics presentationComputer graphics presentation
Computer graphics presentation
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygons
 
Computer graphics - bresenham line drawing algorithm
Computer graphics - bresenham line drawing algorithmComputer graphics - bresenham line drawing algorithm
Computer graphics - bresenham line drawing algorithm
 
Intro to scan conversion
Intro to scan conversionIntro to scan conversion
Intro to scan conversion
 
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSEAU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
 
Unit 2
Unit 2Unit 2
Unit 2
 
Computer graphics 2
Computer graphics 2Computer graphics 2
Computer graphics 2
 
Output primitives computer graphics c version
Output primitives   computer graphics c versionOutput primitives   computer graphics c version
Output primitives computer graphics c version
 
DDA (digital differential analyzer)
DDA (digital differential analyzer)DDA (digital differential analyzer)
DDA (digital differential analyzer)
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterization
 
Apoyo guía-12-2°-medio-ppt.-parábola
Apoyo guía-12-2°-medio-ppt.-parábolaApoyo guía-12-2°-medio-ppt.-parábola
Apoyo guía-12-2°-medio-ppt.-parábola
 
CST 504 Distance in the Cartesian Plane
CST 504 Distance in the Cartesian PlaneCST 504 Distance in the Cartesian Plane
CST 504 Distance in the Cartesian Plane
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - Notes
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 

Andere mochten auch

Andere mochten auch (12)

7. pemrograman struktur
7. pemrograman struktur7. pemrograman struktur
7. pemrograman struktur
 
Open GL 09 scan conversion
Open GL 09 scan conversionOpen GL 09 scan conversion
Open GL 09 scan conversion
 
Pertemuan10 spywareadwaredanspam
Pertemuan10 spywareadwaredanspamPertemuan10 spywareadwaredanspam
Pertemuan10 spywareadwaredanspam
 
Pertemuan 1
Pertemuan 1Pertemuan 1
Pertemuan 1
 
6. pemrograman pointer
6. pemrograman pointer6. pemrograman pointer
6. pemrograman pointer
 
Tarby magazine salafiyah kajen
Tarby magazine  salafiyah kajenTarby magazine  salafiyah kajen
Tarby magazine salafiyah kajen
 
Pcd 11
Pcd 11Pcd 11
Pcd 11
 
Pcd 10
Pcd 10Pcd 10
Pcd 10
 
Pcd 4
Pcd 4Pcd 4
Pcd 4
 
Matlab
MatlabMatlab
Matlab
 
Techarea company profile
Techarea company profileTecharea company profile
Techarea company profile
 
Pengolahan Citra 2 - Pembentukan Citra Digital
Pengolahan Citra 2 - Pembentukan Citra DigitalPengolahan Citra 2 - Pembentukan Citra Digital
Pengolahan Citra 2 - Pembentukan Citra Digital
 

Ähnlich wie Open GL T0074 56 sm1

Output Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and MultimediaOutput Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and Multimediasaranyan75
 
Computer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivesComputer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivessaranyan75
 
Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4Roziq Bahtiar
 
Unit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsUnit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsAmol Gaikwad
 
Computer graphics notes 2 tutorials duniya
Computer graphics notes 2   tutorials duniyaComputer graphics notes 2   tutorials duniya
Computer graphics notes 2 tutorials duniyaTutorialsDuniya.com
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2SanthiNivas
 
Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxKokebe2
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygonsaa11bb11
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons dericationKumar
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxIndhuMcamphil
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxAlamelu
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualAnkit Kumar
 
Lecture _Line Scan Conversion.ppt
Lecture _Line Scan Conversion.pptLecture _Line Scan Conversion.ppt
Lecture _Line Scan Conversion.pptGaganvirKaur
 
elementry-objects-CG give great effort on learning for exam
elementry-objects-CG give great effort on learning for examelementry-objects-CG give great effort on learning for exam
elementry-objects-CG give great effort on learning for examtigag49721
 
Open GL 04 linealgos
Open GL 04 linealgosOpen GL 04 linealgos
Open GL 04 linealgosRoziq Bahtiar
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithmsMohammad Sadiq
 

Ähnlich wie Open GL T0074 56 sm1 (20)

raster algorithm.pdf
raster algorithm.pdfraster algorithm.pdf
raster algorithm.pdf
 
Output Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and MultimediaOutput Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and Multimedia
 
Computer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivesComputer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitives
 
Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4
 
Unit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsUnit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithms
 
Computer graphics notes 2 tutorials duniya
Computer graphics notes 2   tutorials duniyaComputer graphics notes 2   tutorials duniya
Computer graphics notes 2 tutorials duniya
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
 
Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptx
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygons
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
 
03.Scan Conversion.ppt
03.Scan Conversion.ppt03.Scan Conversion.ppt
03.Scan Conversion.ppt
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptx
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptx
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Lecture _Line Scan Conversion.ppt
Lecture _Line Scan Conversion.pptLecture _Line Scan Conversion.ppt
Lecture _Line Scan Conversion.ppt
 
Computer graphics notes
Computer graphics notesComputer graphics notes
Computer graphics notes
 
Computer graphics notes watermark
Computer graphics notes watermarkComputer graphics notes watermark
Computer graphics notes watermark
 
elementry-objects-CG give great effort on learning for exam
elementry-objects-CG give great effort on learning for examelementry-objects-CG give great effort on learning for exam
elementry-objects-CG give great effort on learning for exam
 
Open GL 04 linealgos
Open GL 04 linealgosOpen GL 04 linealgos
Open GL 04 linealgos
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
 

Mehr von Roziq Bahtiar

static and dynamic routing
static and dynamic routingstatic and dynamic routing
static and dynamic routingRoziq Bahtiar
 
Perintah perintah dasar linux Operating Sistem
Perintah perintah dasar linux Operating SistemPerintah perintah dasar linux Operating Sistem
Perintah perintah dasar linux Operating SistemRoziq Bahtiar
 
Pengantar algoritma pemrograman
Pengantar algoritma pemrogramanPengantar algoritma pemrograman
Pengantar algoritma pemrogramanRoziq Bahtiar
 
Flowchart progrm linear bilangan bulat
Flowchart progrm linear bilangan bulatFlowchart progrm linear bilangan bulat
Flowchart progrm linear bilangan bulatRoziq Bahtiar
 
5. pemrograman array dan_string
5. pemrograman array dan_string5. pemrograman array dan_string
5. pemrograman array dan_stringRoziq Bahtiar
 
4. pemrograman fungsi
4. pemrograman fungsi4. pemrograman fungsi
4. pemrograman fungsiRoziq Bahtiar
 
3. teknik looping dalam_pemrograman
3. teknik looping dalam_pemrograman3. teknik looping dalam_pemrograman
3. teknik looping dalam_pemrogramanRoziq Bahtiar
 
2. teknik pemilihan dalam_pemrograman
2. teknik pemilihan dalam_pemrograman2. teknik pemilihan dalam_pemrograman
2. teknik pemilihan dalam_pemrogramanRoziq Bahtiar
 
1. variable identifier dan_tipe_data
1. variable identifier dan_tipe_data1. variable identifier dan_tipe_data
1. variable identifier dan_tipe_dataRoziq Bahtiar
 
3 piksel_dan_histogram
 3 piksel_dan_histogram 3 piksel_dan_histogram
3 piksel_dan_histogramRoziq Bahtiar
 
Open GL T0074 56 sm3
Open GL T0074 56 sm3Open GL T0074 56 sm3
Open GL T0074 56 sm3Roziq Bahtiar
 
Open GL T0074 56 sm2
Open GL T0074 56 sm2Open GL T0074 56 sm2
Open GL T0074 56 sm2Roziq Bahtiar
 

Mehr von Roziq Bahtiar (19)

static and dynamic routing
static and dynamic routingstatic and dynamic routing
static and dynamic routing
 
Perintah perintah dasar linux Operating Sistem
Perintah perintah dasar linux Operating SistemPerintah perintah dasar linux Operating Sistem
Perintah perintah dasar linux Operating Sistem
 
Pengantar algoritma pemrograman
Pengantar algoritma pemrogramanPengantar algoritma pemrograman
Pengantar algoritma pemrograman
 
Flowchart progrm linear bilangan bulat
Flowchart progrm linear bilangan bulatFlowchart progrm linear bilangan bulat
Flowchart progrm linear bilangan bulat
 
5. pemrograman array dan_string
5. pemrograman array dan_string5. pemrograman array dan_string
5. pemrograman array dan_string
 
4. pemrograman fungsi
4. pemrograman fungsi4. pemrograman fungsi
4. pemrograman fungsi
 
3. teknik looping dalam_pemrograman
3. teknik looping dalam_pemrograman3. teknik looping dalam_pemrograman
3. teknik looping dalam_pemrograman
 
2. teknik pemilihan dalam_pemrograman
2. teknik pemilihan dalam_pemrograman2. teknik pemilihan dalam_pemrograman
2. teknik pemilihan dalam_pemrograman
 
1. variable identifier dan_tipe_data
1. variable identifier dan_tipe_data1. variable identifier dan_tipe_data
1. variable identifier dan_tipe_data
 
Alpro tutor
Alpro tutorAlpro tutor
Alpro tutor
 
Pcd 7
Pcd 7Pcd 7
Pcd 7
 
Pcd 5
Pcd 5Pcd 5
Pcd 5
 
Eigen
EigenEigen
Eigen
 
3 piksel_dan_histogram
 3 piksel_dan_histogram 3 piksel_dan_histogram
3 piksel_dan_histogram
 
Pcd 8
Pcd 8Pcd 8
Pcd 8
 
2 pengolahan_citra
 2 pengolahan_citra 2 pengolahan_citra
2 pengolahan_citra
 
Open GL T0074 56 sm3
Open GL T0074 56 sm3Open GL T0074 56 sm3
Open GL T0074 56 sm3
 
Open GL T0074 56 sm2
Open GL T0074 56 sm2Open GL T0074 56 sm2
Open GL T0074 56 sm2
 
Open GL Tutorial06
Open GL Tutorial06Open GL Tutorial06
Open GL Tutorial06
 

Kürzlich hochgeladen

Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 

Kürzlich hochgeladen (20)

Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 

Open GL T0074 56 sm1

  • 1. CS 4731: Computer Graphics Lecture 18: Raster Graphics Part 1 Emmanuel Agu
  • 2. 2D Graphics Pipeline Object World Coordinates Object subset window to viewport mapping Object Screen coordinates RasterizationDisplay Applying world window Clipping Simple 2D Drawing Pipeline
  • 3. Rasterization (Scan Conversion) n Convert high-level geometry description to pixel colors in the frame buffer n Example: given vertex x,y coordinates determine pixel colors to draw line n Two ways to create an image: n Scan existing photograph n Procedurally compute values (rendering) Viewport Transformation Rasterization
  • 4. Rasterization n A fundamental computer graphics function n Determine the pixels’ colors, illuminations, textures, etc. n Implemented by graphics hardware n Rasterization algorithms n Lines n Circles n Triangles n Polygons
  • 5. Rasterization Operations n Drawing lines on the screen n Manipulating pixel maps (pixmaps): copying, scaling, rotating, etc n Compositing images, defining and modifying regions n Drawing and filling polygons n Previously glBegin(GL_POLYGON), etc n Aliasing and antialiasing methods
  • 6. Line drawing algorithm n Programmer specifies (x,y) values of end pixels n Need algorithm to figure out which intermediate pixels are on line path n Pixel (x,y) values constrained to integer values n Actual computed intermediate line values may be floats n Rounding may be required. E.g. computed point (10.48, 20.51) rounded to (10, 21) n Rounded pixel value is off actual line path (jaggy!!) n Sloped lines end up having jaggies n Vertical, horizontal lines, no jaggies
  • 7. Line Drawing Algorithm 0 1 2 3 4 5 6 7 8 9 10 11 12 8 7 6 5 4 3 2 1 Line: (3,2) -> (9,6) ? Which intermediate pixels to turn on?
  • 8. Line Drawing Algorithm n Slope-intercept line equation n y = mx + b n Given two end points (x0,y0), (x1, y1), how to compute m and b? (x0,y0) (x1,y1) dx dy 01 01 xx yy dx dy m − − == 0*0 xmyb −=
  • 9. Line Drawing Algorithm n Numerical example of finding slope m: n (Ax, Ay) = (23, 41), (Bx, By) = (125, 96) 5392.0 102 55 23125 4196 == − − = − − = AxBx AyBy m
  • 10. Digital Differential Analyzer (DDA): Line Drawing Algorithm (x0,y0) (x1,y1) dx dy §Walk through the line, starting at (x0,y0) §Constrain x, y increments to values in [0,1] range §Case a: x is incrementing faster (m < 1) §Step in x=1 increments, compute and round y §Case b: y is incrementing faster (m > 1) §Step in y=1 increments, compute and round x m<1 m>1 m=1
  • 11. DDA Line Drawing Algorithm (Case a: m < 1) (x0, y0) x = x0 + 1 y = y0 + 1 * m Illuminate pixel (x, round(y)) x = x + 1 y = y + 1 * m Illuminate pixel (x, round(y)) … Until x == x1 (x1,y1) x = x0 y = y0 Illuminate pixel (x, round(y)) myy kk +=+1
  • 12. DDA Line Drawing Algorithm (Case b: m > 1) y = y0 + 1 x = x0 + 1 * 1/m Illuminate pixel (round(x), y) y = y + 1 x = x + 1 /m Illuminate pixel (round(x), y) … Until y == y1 x = x0 y = y0 Illuminate pixel (round(x), y) (x1,y1) (x0,y0) m xx kk 1 1 +=+
  • 13. DDA Line Drawing Algorithm Pseudocode compute m; if m < 1: { float y = y0; // initial value for(int x = x0;x <= x1; x++, y += m) setPixel(x, round(y)); } else // m > 1 { float x = x0; // initial value for(int y = y0;y <= y1; y++, x += 1/m) setPixel(round(x), y); } n Note: setPixel(x, y) writes current color into pixel in column x and row y in frame buffer
  • 14. Line Drawing Algorithm Drawbacks n DDA is the simplest line drawing algorithm n Not very efficient n Round operation is expensive n Optimized algorithms typically used. n Integer DDA n E.g.Bresenham algorithm (Hill, 10.4.1) n Bresenham algorithm n Incremental algorithm: current value uses previous value n Integers only: avoid floating point arithmetic n Several versions of algorithm: we’ll describe midpoint version of algorithm
  • 15. Bresenham’s Line-Drawing Algorithm n Problem: Given endpoints (Ax, Ay) and (Bx, By) of a line, want to determine best sequence of intervening pixels n First make two simplifying assumptions (remove later): n (Ax < Bx) and n (0 < m < 1) n Define n Width W = Bx – Ax n Height H = By - Ay (Bx,By) (Ax,Ay)
  • 16. Bresenham’s Line-Drawing Algorithm n Based on assumptions: n W, H are +ve n H < W n As x steps in +1 increments, y incr/decr by <= +/–1 n y value sometimes stays same, sometimes increases by 1 n Midpoint algorithm determines which happens
  • 17. Bresenham’s Line-Drawing Algorithm (x0, y0) M = (x0 + 1, Y0 + ½) Build equation of line through and compare to midpoint … (x1,y1) What Pixels to turn on or off? Consider pixel midpoint M(Mx, My) M(Mx,My) If midpoint is above line, y stays same If midpoint is below line, y increases + 1
  • 18. Bresenham’s Line-Drawing Algorithm n Using similar triangles: n H(x – Ax) = W(y – Ay) n -W(y – Ay) + H(x – Ax) = 0 n Above is ideal equation of line through (Ax, Ay) and (Bx, By) n Thus, any point (x,y) that lies on ideal line makes eqn = 0 n Double expression (to avoid floats later), and give it a name, F(x,y) = -2W(y – Ay) + 2H(x – Ax) W H Axx Ayy = − − (Bx,By) (Ax,Ay) (x,y)
  • 19. Bresenham’s Line-Drawing Algorithm n So, F(x,y) = -2W(y – Ay) + 2H(x – Ax) n Algorithm, If: n F(x, y) < 0, (x, y) above line n F(x, y) > 0, (x, y) below line n Hint: F(x, y) = 0 is on line n Increase y keeping x constant, F(x, y) becomes more negative
  • 20. Bresenham’s Line-Drawing Algorithm n Example: to find line segment between (3, 7) and (9, 11) F(x,y) = -2W(y – Ay) + 2H(x – Ax) = (-12)(y – 7) + (8)(x – 3) n For points on line. E.g. (7, 29/3), F(x, y) = 0 n A = (4, 4) lies below line since F = 44 n B = (5, 9) lies above line since F = -8
  • 21. Bresenham’s Line-Drawing Algorithm (x0, y0) M = (x0 + 1, Y0 + ½) If F(Mx,My) < 0, M lies above line, shade lower pixel (same y as before) … (x1,y1) What Pixels to turn on or off? Consider pixel midpoint M(Mx, My) M(Mx,My) If F(Mx,My) > 0, M lies below line, shade upper pixel
  • 22. Can compute F(x,y) incrementally Initially, midpoint M = (Ax + 1, Ay + ½) F(Mx, My) = -2W(y – Ay) + 2H(x – Ax) = 2H – W Can compute F(x,y) for next midpoint incrementally If we increment x + 1, y stays same, compute new F(Mx,My) F(Mx, My) += 2H If we increment x +1, y + 1 F(Mx, My) -= 2(W – H)
  • 23. Bresenham’s Line-Drawing Algorithm Bresenham(IntPoint a, InPoint b) { // restriction: a.x < b.x and 0 < H/W < 1 int y = a.y, W = b.x – a.x, H = b.y – a.y; int F = 2 * H – W; // current error term for(int x = a.x; x <= b.x; x++) { setpixel at (x, y); // to desired color value if F < 0 F = F + 2H; else{ Y++, F = F + 2(H – W) } } } n Recall: F is equation of line
  • 24. Bresenham’s Line-Drawing Algorithm n Final words: we developed algorithm with restrictions 0 < m < 1 and Ax < Bx n Can add code to remove restrictions n To get the same line when Ax > Bx (swap and draw) n Lines having m > 1 (interchange x with y) n Lines with m < 0 (step x++, decrement y not incr) n Horizontal and vertical lines (pretest a.x = b.x and skip tests) n Important: Read Hill 10.4.1