Introduction to Computer Graphics - University of California, San
Transcript of Introduction to Computer Graphics - University of California, San
![Page 1: Introduction to Computer Graphics - University of California, San](https://reader035.fdocuments.us/reader035/viewer/2022071600/613d1d4e736caf36b7597bd9/html5/thumbnails/1.jpg)
Introduction to Computer Graphics
Farhana Bandukwala, PhDLecture 2: Raster Graphics
![Page 2: Introduction to Computer Graphics - University of California, San](https://reader035.fdocuments.us/reader035/viewer/2022071600/613d1d4e736caf36b7597bd9/html5/thumbnails/2.jpg)
Outline
• More logistics• Raster vs Vector graphics(Angel, Section 1.2)
• Advantages and Drawbacks• Algorithms (Angel, Section 8.9)
• Bit and Pixel operations in Open GL (Angel, Chapter 7)
![Page 3: Introduction to Computer Graphics - University of California, San](https://reader035.fdocuments.us/reader035/viewer/2022071600/613d1d4e736caf36b7597bd9/html5/thumbnails/3.jpg)
Logistics
• Web accounts, class web page• Visual C++ tutorial• Opengl: library to simplify graphics code
– Windows libraries: opengl32.lib,glu32.lib,glut32.lib
– headers:• GL/gl.h, GL/glu.h, GL/glut.h
![Page 4: Introduction to Computer Graphics - University of California, San](https://reader035.fdocuments.us/reader035/viewer/2022071600/613d1d4e736caf36b7597bd9/html5/thumbnails/4.jpg)
What is an image?
• A 2-D array of intensity values which depict a scene• Analog: picture from a regular camera
– Pixel size is infinitesimally small– Maximum resolution & bandwidth
• Digital: scanned image, CCD or digital camera– Pixel size is finite– Quality of representation related to pixel size, number of pixels
• Graphics provides means to display an image on an output device (monitor, printed media, etc.)
• Image processing consists of pixel manipulation NOT display
![Page 5: Introduction to Computer Graphics - University of California, San](https://reader035.fdocuments.us/reader035/viewer/2022071600/613d1d4e736caf36b7597bd9/html5/thumbnails/5.jpg)
Vector graphics• Used in display devices
of ’60s• Components:
– Display buffer: stores display list
– Display processor: executes commands
– CRT: beam deflected accordingly
• Advantages: – smooth lines
• Drawbacks:– Performance– no filled regions
![Page 6: Introduction to Computer Graphics - University of California, San](https://reader035.fdocuments.us/reader035/viewer/2022071600/613d1d4e736caf36b7597bd9/html5/thumbnails/6.jpg)
Raster graphics
• Raster: matrix of pixels representing screen space
• Primitives stored in buffer (memory) as pixels
• Video controller scans out buffer
• Beam’s intensity determined by each pixel
• Bitmap vs Pixmap
![Page 7: Introduction to Computer Graphics - University of California, San](https://reader035.fdocuments.us/reader035/viewer/2022071600/613d1d4e736caf36b7597bd9/html5/thumbnails/7.jpg)
Vector vs Raster Graphics
![Page 8: Introduction to Computer Graphics - University of California, San](https://reader035.fdocuments.us/reader035/viewer/2022071600/613d1d4e736caf36b7597bd9/html5/thumbnails/8.jpg)
Advantages of Raster Graphics
• Faster, lower cost refresh hardware• True filled areas: realistic images • Refresh rate independent of scene
complexity
![Page 9: Introduction to Computer Graphics - University of California, San](https://reader035.fdocuments.us/reader035/viewer/2022071600/613d1d4e736caf36b7597bd9/html5/thumbnails/9.jpg)
Drawbacks
• Primitives have to be scan converted• Aliasing• Solution: powerful algorithms
![Page 10: Introduction to Computer Graphics - University of California, San](https://reader035.fdocuments.us/reader035/viewer/2022071600/613d1d4e736caf36b7597bd9/html5/thumbnails/10.jpg)
Simple Raster Graphics Package
• Input: primitives, attributes, application controls• Output: raster into frame buffer• Package scan converts, clips and does anti-
aliasing
Application model
Application program
SRGP Display hardware
Output primitives
Output attributes
Canvas and input controls
Input measures
![Page 11: Introduction to Computer Graphics - University of California, San](https://reader035.fdocuments.us/reader035/viewer/2022071600/613d1d4e736caf36b7597bd9/html5/thumbnails/11.jpg)
Scan converting lines
• Initialize: x0=xmin, y0=ymin
• Basic increment: ∆x=1, yi+1 = yi+m• Simple but computationally expensive (rounding)
![Page 12: Introduction to Computer Graphics - University of California, San](https://reader035.fdocuments.us/reader035/viewer/2022071600/613d1d4e736caf36b7597bd9/html5/thumbnails/12.jpg)
Scan conversion: contd
• Midpoint Line: – Compute difference of distances from E to Q, NE to Q– Use sign of difference to select next pixel (E or NE)– If midpoint above line choose E, otherwise choose NE– Use symmetry for other quarters
(Xp,Yp)
M
E
NE
Q
![Page 13: Introduction to Computer Graphics - University of California, San](https://reader035.fdocuments.us/reader035/viewer/2022071600/613d1d4e736caf36b7597bd9/html5/thumbnails/13.jpg)
Scan converting circles
• Basic y=+/-sqrt(r2-x2)• Speedups:
– Draw quarter circle & use symmetry– Midpoint circle algorithm
ME
SE
![Page 14: Introduction to Computer Graphics - University of California, San](https://reader035.fdocuments.us/reader035/viewer/2022071600/613d1d4e736caf36b7597bd9/html5/thumbnails/14.jpg)
Scan converting filled polygons
• Find all intersections (in green) at a scan line• Sort in ascending x value• Using parity checks, fill pixels along scan line
(initially even parity, flip parity at intersection, color pixel at odd parity)
![Page 15: Introduction to Computer Graphics - University of California, San](https://reader035.fdocuments.us/reader035/viewer/2022071600/613d1d4e736caf36b7597bd9/html5/thumbnails/15.jpg)
Clipping
• Simple BBox test• Each polygon edge tested against each
rectangle edge• New vertices added if necessary
![Page 16: Introduction to Computer Graphics - University of California, San](https://reader035.fdocuments.us/reader035/viewer/2022071600/613d1d4e736caf36b7597bd9/html5/thumbnails/16.jpg)
Anti Aliasing
• Assuming finite width primitives, • Pixel’s intensity proportional to amount of area
covered (unweighted area sampling)• Weighted area sampling: Radially decreasing
weights from pixel center
![Page 17: Introduction to Computer Graphics - University of California, San](https://reader035.fdocuments.us/reader035/viewer/2022071600/613d1d4e736caf36b7597bd9/html5/thumbnails/17.jpg)
Pixel operations in Open GL
• Various buffers: color, depth, stencil• Logic operations on bitmaps & pixmaps• Pack/Unpack to convert pixel to/from OpenGL
format• Bitmaps as masks• Design raster fonts• Look up tables• For help with picking• Texture mapping