310482: Graphics Programming
description
Transcript of 310482: Graphics Programming
04/21/23
310482: Graphics Programming
Seree Chinodom
[email protected]://www.compsci.buu.ac.th/~seree/lecture/310482
04/21/23
Display Technologies
Cathode Ray Tubes (CRTs)– Most common display device today– Evacuated glass bottle– Extremely high voltage– Heating element (filament)– Electrons pulled towards
anode focusing cylinder– Vertical and horizontal deflection plates– Beam strikes phosphor coating on front of tube
04/21/23
Electron Gun
Contains a filament that, when heated, emits a stream of electrons
Electrons are focused with an electromagnet into a sharp beam and directed to a specific point of the face of the picture tube
The front surface of the picture tube is coated with small phospher dots
When the beam hits a phospher dot it glows with a brightness proportional to the strength of the beam and how often it is excited by the beam
04/21/23
Display Technologies: CRTs
Vector Displays– Early computer displays: basically an oscilloscope– Control X,Y with vertical/horizontal plate voltage – Often used intensity as Z
Name two disadvantages Just does wireframe
Complex scenes visible flicker
04/21/23
Display Technologies: CRTs
Raster Displays– Raster: A rectangular array of points or dots– Pixel: One dot or picture element of the raster– Scan line: A row of pixels
04/21/23
Display Technologies: CRTs
Raster Displays– Black and white television: an oscilloscope with a
fixed scan pattern: left to right, top to bottom– To paint the screen, computer needs to
synchronize with the scanning pattern of raster Solution: special memory to buffer image with scan-out
synchronous to the raster. We call this the framebuffer.
04/21/23
Display Technologies: CRTs
Phosphers– Flourescence: Light emitted while the phospher is
being struck by electrons– Phospherescence: Light emitted once the
electron beam is removed– Persistence: The time from the removal of the
excitation to the moment when phospherescence has decayed to 10% of the initial light output
04/21/23
Display Technologies: CRTs
Raster Displays– Frame must be “refreshed” to draw new images– As new pixels are struck by electron beam, others
are decaying– Electron beam must hit all pixels frequently to
eliminate flicker– Critical fusion frequency
Typically 60 times/sec Varies with intensity, individuals, phospher persistence,
lighting...
04/21/23
Display Technologies: CRTs
Raster Displays– Interlaced Scanning– Assume can only scan 30 times / second– To reduce flicker, divide frame into two “fields” of
odd and even lines
1/30 Sec 1/30 Sec1/60 Sec 1/60 Sec 1/60 Sec 1/60 SecField 1 Field 1Field 2 Field 2
Frame Frame
04/21/23
Display Technologies: CRTs
Raster Displays– Scanning (left to right, top to bottom)
Vertical Sync Pulse: Signals the start of the next field Vertical Retrace: Time needed to get from the bottom of
the current field to the top of the next field Horizontal Sync Pulse: Signals the start of the new scan
line Horizontal Retrace: The time needed to get from the end
of the current scan line to the start of the next scan line
04/21/23
Display Technology: Color CRTs
Color CRTs are much more complicated– Requires manufacturing very precise geometry– Uses a pattern of color phosphors on the screen:
– Why red, green, and blue phosphors?Delta electron gun arrangement In-line electron gun arrangement
04/21/23
Display Technology: Color CRTs
Color CRTs have– Three electron guns– A metal shadow mask to differentiate the beams
04/21/23
Display Technology: Raster
Raster CRT pros:– Allows solids, not just wireframes– Leverages low-cost CRT technology (i.e., TVs)– Bright! Display emits light
Cons:– Requires screen-size memory array– Discreet sampling (pixels)– Practical limit on size (call it 40 inches)– Bulky– Finicky (convergence, warp, etc)
04/21/23
Display Technology: LCDs
Liquid Crystal Displays (LCDs)– LCDs: organic molecules, naturally in crystalline
state, that liquefy when excited by heat or E field– Crystalline state twists polarized light 90º
04/21/23
Display Technology: LCDs
Transmissive & reflective LCDs:– LCDs act as light valves, not light emitters, and
thus rely on an external light source.– Laptop screen: backlit, transmissive display– Palm Pilot/Game Boy: reflective display
04/21/23
Display Technology: Plasma
Plasma display panels– Similar in principle to
fluorescent light tubes– Small gas-filled capsules
are excited by electric field,emits UV light
– UV excites phosphor– Phosphor relaxes, emits
some other color
04/21/23
Display Technology
Plasma Display Panel Pros– Large viewing angle– Good for large-format displays– Fairly bright
Cons– Expensive– Large pixels (~1 mm versus ~0.2 mm)– Phosphors gradually deplete– Less bright than CRTs, using more power
04/21/23
Display Technology: DMDs
Digital Micromirror Devices (projectors)– Microelectromechanical (MEM) devices,
fabricated with VLSI techniques
04/21/23
Display Technology: DMDs
DMDs are truly digital pixels Vary grey levels by modulating pulse length Color: multiple chips, or color-wheel Great resolution Very bright Flicker problems
04/21/23
Display Technologies: Organic LED Arrays Organic Light-Emitting Diode (OLED) Arrays
– The display of the future? Many think so.– OLEDs function like regular semiconductor LEDs– But with thin-film polymer construction:
Thin-film deposition or vacuum deposition process…not grown like a crystal, no high-temperature doping
Thus, easier to create large-area OLED sheet
04/21/23
Display Technologies: Organic LED Arrays OLED pros:
– Transparent– Flexible– Light-emitting, and quite bright (daylight visible)– Large viewing angle– Fast (< 1 microsecond off-on-off)– Can be made large or small
OLED cons:– Not quite there yet (96x64 displays…)– Not very robust, display lifetime a key issue
04/21/23
Raster Scan Displays
Beam of electrons deflected onto a phosphor coated screen– Phosphors emit light when excited by the electro
ns– Phosphor brightness decays -- need to refresh th
e display– Phosphors make up screen elements called pixel
s
04/21/23
Basic Definitions
Raster: A rectangular array of points or dots.Pixel (Pel): One dot or picture element of the rasterScan line: A row of pixels
Video raster devices display an image by sequentially drawing out the pixels of the scan lines that form the raster.
04/21/23
Frame Buffers
A frame buffer may be thought of as computer memory organized as a two-dimensional array with each (x,y) addressable location corresponding to one pixel.
Bit Planes or Bit Depth is the number of bits corresponding to each pixel.
A typical frame buffer resolution might be
640 x 480 x 81280 x 1024 x 81280 x 1024 x 24
04/21/23
1-Bit Memory, Monochrome Display (Bitmap Display)
Electron Gun
1 bit 2 levels
04/21/23
3-Bit Color Display
3
red
green
blue
COLOR: black red green blue yellow cyan magenta white
R G B
0 0 0
1 0 0
0 1 0
0 0 1
1 1 0
0 1 1
1 0 1
1 1 1
04/21/23
True Color Display
Green
Red
Blue
8
8
8
24 bitplanes, 8 bits per color gun.224 = 16,777,216
04/21/23
Color Map Look-Up Tables
Extends the number of colors that can be displayed by a given number of bit-planes.
67
100110100001
0
67
255
10011010 0001
R G B
RED
GREEN
BLUE
Pixel displayedat x', y'
Pixel inbit mapat x', y'
0 x0
y
xmax
maxy
Frame buffer Look-up table Display
04/21/23
Pseudo color
0
1
2
3
254
255
RED GREEN BLUE
256 colors chosen from a palette of 16,777,216.
Each entry in the color map LUT can be user defined.
28 x 24 Color Map LUT
04/21/23
Drawing
Most computer generated images made up of geometric primitives (polygons, lines, points)
Application draws them by setting bits in the
framebuffer Most graphics applications involve scene dat
abase management
SceneDatabase
GraphicApplication
DeviceDriverFramebuffer
Disp
lay
04/21/23
A DDA Line Drawing Function
Line(int x1, int y1, int x2, int y2) {
int dx = x1 - x2, dy =y2 -y1;int n = max(abs(dx),abs(dy));float dt = n, dxdt = dx/dt, dydt = dy/dt;float x = x1, y = y1;while (n--){
DrawPoint( round(x), round(y) );x +=dxdt;y +=dydt;
}}
04/21/23
We Can Do Better Than That...
Get rid of all those nasty floating point operations The idea: find the next pixel from the current one
So which of the green pixels is next?
04/21/23
The Key
We’re only ever going to go right one pixel, or up and right one pixel (if the slope of the line is between 0 and 1). Call these two choices “E” and “NE”
Let’s think of pixels as “lattice points” on a grid Given an X coordinate, we only need to choose betw
een y and y+1 (y is the Y coordinate of the last pixel)
04/21/23
The Midpoint Test
Look at the vertical grid line that our line intersects
On which side of the midpoint (y+1/2) does the intersection lie?
If it’s above the midpoint, go NE, otherwise go E
04/21/23
Our Example
04/21/23
Implicit Functions
Normally, a line is defined as y= mx +b Instead, define ,F(x,y) = ax +by + c and let th
e line be everywhere where F(x,y) = 0 Now, if F(x,y) > 0 , we’re “above” the line, an
d if F(x,y) < 0 , we’re “below” the line
04/21/23
Who Cares?
We can evaluate the implicit line function at the
midpoint to figure out where to draw next! In fact, we can use the last function evaluati
on to find the next one cheaply! For ANY x, y:
F(x + 1,y) - F(x,y) = a
F(x + 1,y + 1) - F(x,y) = a - b
04/21/23
Midpoint Algorithm
Line(int x1, int y1, int x2, int y2){
int dx = x2 - x1, dy =y2 -y1;int e = 2*dy - dx;int incrE = 2*dy, incrNE = 2*(dy-dx);int x = x1, y = y1;DrawPoint( x, y );while (x < x2) {
x++;if ( e <= 0 ) { e += incrE; }else { y++; e += incrNE; }DrawPoint( x, y );
}}
“e” holds the implicit function evaluation at each x value (actually, it’s multiplied by 2, but all we care about is the sign).
Easy extension for lines with arbitrary slopes