Transcript Document

Chapter 2
Overview of Graphics Systems
Some slides adapted from Benjamin Lok, Ilmi Yoon and Falko Kuester
Expanded by Jozef Goetz
Glossary
• CG API – Computer Graphics Application
Programming Interface
• tbs – to be specified
• FoV – Field of View
• +’s – pluses, advantages
• -’s – minuses, disadvantages
Expanded by Jozef Goetz
Glossary
• CG – Computer Graphics
• Rasterization: The process of determining values
for the pixels in a rendered image. Translating an
image into pixels. Also called scan conversion.
• Texture refers to the surface quality (color).
• Texture mapping is a method of adding realism to a
computer-generated graphic.
– When a picture is mapped onto an object, the
correspondence between the picture's pixels and points on
the object's surface is calculated.
• Specular: reflective, especially light from materials
with glossy surfaces
Expanded by Jozef Goetz
Glossary
• Bump mapping: The process of creating and
displaying a texture where the values of the texture
are used to simulate the bumpiness of an object's
surface.
– Bump mapping is used to add detail to an image without
increasing the number of polygons.
– Bump maps do not move the geometry of an object, but
they do affect the shading of a surface, giving the illusion
of a pattern being embossed on the surface
– Bumps are applied by matching up a series of grayscale
pixels with colored pixels on the rendered, colored object.
Lighter grayscale pixels create a sense of maximum relief or
maximum
Expanded by Jozef Goetz
Usually for graphics, we start at top left corner
and work our way across and down
Same as raster orientation
Expanded by Jozef Goetz
Outline
• Image Basics
• Graphics Hardware
– Input
• Describing something to the computer
– Computation
• Computing what we want to draw
– Output
• Final representation
Expanded by Jozef Goetz
PC Graphics – Physical Organization
• Video cards communicates via AGP Accelerated
Graphics Port
– Pentium II and beyond
– a high-bandwidth channel between the CPU chipset and
the graphics processor (DIME = Direct Memory Execute)
– faster animation
Expanded by Jozef Goetz
PC Graphics – Logical Organization
Expanded by Jozef Goetz
PC Graphics – Logical Organization
•
DirectX = DirectDraw + Direct3D
+ DirectSound + DirectInput +
higher-level stuff
– Microsoft OS’s only
•
OpenGL is an open 3D graphics
API
– Built into MacOS, Windows
– Available for most other platforms
•
GDI (Graphics Device Interface)
provides API to draw lines, curves,
polygons etc
–
–
•
Equivalent of Mac's Quickdraw
Included by <windows.h>
Games use a different interface
(DirectX or OpenGL) to get high
speed full-screen access to VRAM
Expanded by Jozef Goetz
Human Vision
• Brightness is defined as perceived intensity
• Visual Acuity measures how closely two
points can be placed and still distinguished
(resolution)
– Signal sent along optic nerves to visual cortex for
very sophisticated high-level processing (hot
research topic!)
– Respond differently to different wavelengths
according to the CIE standard observer curve
Expanded by Jozef Goetz
Human Vision
• Cones : color sensing receptors
– high concentration at the center
– types (pigment-based)
– small, medium and long wavelength
•
3:7:14 ratio
– 6.5 mln cone photoreceptors per eye
•
Rod : non-color sensing
– none at the center
– increase to max at ~18 degrees
– 120 mln rod photoreceptors per eye
• color information is limited at periphery
• 1 mln fibers are leaving the eye
Hood and Finkelstein, 1986
Expanded by Jozef Goetz
The Eye
The retina is largely composed of rods and cones. We
concentrate on the cones as they determine color perception.
Expanded by Jozef Goetz
Spatial Vision
•
•
•
•
•
•
•
•
Depth perception
Relative position / occlusion
Shading
Sharpness
Size
Perspective
Structure
Motion - parallax
Expanded by Jozef Goetz
Expanded by Jozef Goetz
PC Graphics – Physical Organization
• Video cards communicates via AGP Accelerated
Graphics Port
– Pentium II and beyond
– a high-bandwidth channel between the CPU chipset and
the graphics processor (DIME = Direct Memory Execute)
– faster animation
Expanded by Jozef Goetz
Raster Graphics System Architecture
Image © P Hanrahan
Expanded by Jozef Goetz
Expanded by Jozef Goetz
Home PC Architecture
Framebuffer FB - A block of memory,
dedicated to graphics output, that holds
the contents of what will be displayed.
Expanded by Jozef Goetz
Image © P Hanrahan
Computer Memory Model
• CPU + Cache memory + • Graphics memory
Main memory
– Used to be limited to
separate amount on
• Cache memory is fast but
graphics card
expensive so (still often)
– Modern idea is to partition
only have small amount
main memory dynamically
e.g. 512kBytes available
(i.e. by software instruction)
• Main memory relatively • Modern idea is to map
plentiful (e.g. GBytes) but memory to the display
slow
– Independent of display
hardware type
Expanded by Jozef Goetz
Memory & Graphics
• Idea is that we can write programs that interact with
the graphical display device simply by writing to a
predetermined area of the computer’s memory
– Known as Bitmap graphics
• The bits are mapped to the pixels
• Flexible, portable software
• Independent of Hardware & Operating System
Expanded by Jozef Goetz
Pixels
• Pixel or sometimes “pel” Picture Element
• Each pixel is a sample that can be rendered as a
dot or rectangle on the screen
• Pixel - The most basic addressable image element in
a screen
– CRT - Color triad (RGB phosphor dots)
– LCD - Single color element
simple a transistor logic gate assembly on a flat panel
display
• Screen Resolution - measure of number of pixels on
a screen (m by n)
– m - Horizontal screen resolution
– n - Vertical screen resolution
Expanded by Jozef Goetz
Graphical Devices
• Devices
– mouse,
– stereo glasses,
– tracker ball,
– light pen,
– touch screen,
– 3d-wand,
– “rat”,
– sensor gloves,
– head tracker,
– iris tracker,…
• Mouse - most well known
device
• Buttons, and scan movements
• Jargon ideas that have become
common:
– Drag
– Click
– Double-Click
– Left -Click
• Main idea is to let you
• Even Mouse varies in
form factor and number of
buttons
specify a location in a space
e.g. x,y (or x,y,z) coordinates
Expanded by Jozef Goetz
Coordinate Systems
• Pixel Coordinate System - rows and columns
• Rectilinear
– Formed or enclosed by straight lines to create a rectangle.
• Usually for graphics, we start at top left corner
– and work our way across and down
– Same as raster orientation
• Array[row][column]
• Row major used in C and C+
– last index moves fastest in memory
• Not all languages do it this way – e.g. Fortran uses column major (first
index moves fastest)
Expanded by Jozef Goetz
Y
Cartesian Coordinates
x
y
• Often
we use the Cartesian coordinate convention i.e.
x,y coordinates (or x,y,z in 3D) and map this to our
display
• Usually
– column corresponds to x,
– row corresponds to y
• This works if we know the max min values.
– Common values are e.g. 640 columns x 320 rows
– Or 1024 x 768 or better
– Aspect ratio is the ratio of these e.g. 4:3
• Chosen to suit the common display devices e.g. TV screens or
monitors
Expanded by Jozef Goetz
Expanded by Jozef Goetz
Drawing Space or Canvas
• We do not want to write our application programs
worrying about pixel resolutions
• To draw primitives we may have libraries
– often they will support more general coordinates
• Library of utilities
– e.g. drawDot( int x, int y);
– or drawLine( x1, y1, x2, y2 );
Expanded by Jozef Goetz
Graphics Definitions
• Point
– a location in space, 2D or 3D
– sometimes denotes one pixel
• Line
– straight path connecting two points
– beginning and end on points
– infinitesimal (immeasurably small) width,
consistent density
Expanded by Jozef Goetz
Graphics Definitions
• Vertex
– point in 3D
• Edge
– line in 3D connecting two vertices
• Polygon/Face/Facet
– arbitrary shape formed by connected vertices
– fundamental unit of 3D computer graphics
Expanded by Jozef Goetz
Memory & Graphics
• Idea is that we write to a predetermined area of
the computer’s memory
– Known as Bitmap graphics
– The bits are mapped to the pixels
Expanded by Jozef Goetz
Raster Model - Pixels
• Each pixel is a sample that can be rendered as a
dot or rectangle on the screen
• Might be implemented as
– small area of phosphor on a monochrome monitor
– Or three areas of e.g. red, green and blue phosphors
for color
– Or simple a transistor logic gate assembly on a flat
panel display
• Often try to design pixels as squares but not always
Expanded by Jozef Goetz
Overlap Model
• Pixel value is a weighted average
over a spot with radius i.
• Weighting function is conical, or
more optimally gaussian.
• CRT pixels overlap.
2i
A Pixel is NOT just a little
square.
Expanded by Jozef Goetz
Colors in Brief
• Red Green Blue
– still most common
• We specify separate RGB
values for each pixel
• These will conveniently pack
into a computer word of 4
bytes, one byte for each
entity
– They map to intensities
– All colors can be expressed as
combination of these
• Sometimes also an “alpha”
(transparency value)
Expanded by Jozef Goetz
– 1 Byte gives us 256 values hence numbers of colors
– Need not use this resolution
– Can also use Look-up tables
to save memory
Two Dimensional Images
• Images (at least
the ones in this
class) are two
dimensional
shapes.
• The two axes we
will label as X
(horizontal), and
Y (vertical).
+Y
Y
Axis
(0,0)
Expanded by Jozef Goetz
X Axis
+X
Hardware Pipeline
Input
Computation
Output
We want to draw a rectangle, how do we describe it to a computer?
Model (n) - object
description that a
computer
understands.
Expanded by Jozef Goetz
Partition the space
1. Define a set of
points (vertices)
in 2D space.
(7,9)
(14,9)
2. Given a set of
vertices, draw
lines between
consecutive
vertices.
(7,3)
(14,3)
Vertex (pl. Vertices) - a point in 2 or 3 dimensional space.
Expanded by Jozef Goetz
Record every position
Bitmap - a rectangular array of bits mapped one-to-one with
pixels.
Expanded by Jozef Goetz
Position relative
Vector display system - graphical output system that was
based on line drawings/strokes (as opposed to pixels). Also
known as: random, calligraphic, or stroke displays.
Expanded by Jozef Goetz
Representing Objects
• Most common method is the VERTEX
method.
– Define the object as a set of points with
connectivity information.
• Why is connectivity important?
Connectivity - information that defines
which vertices are connected to which
other vertices via edges.
Edge - connects two vertices
Expanded by Jozef Goetz
How do we do this?
Expanded by Jozef Goetz
Input Devices
• Locator Devices
• Keyboard
–
•
2-D Locators:
–
•
Mouse, light pen, data tablet
3-D Locators
–
•
Input of characters
Trackers, 3-D Mice
Haptics (Force Feedback)
–
Phantom
• Scanner
– Images
– Laser
• Cameras (research)
• Misc
–
Dials, switches, video streams
Expanded by Jozef Goetz
Locator Devices
p.57-66
When queried, locator devices return a
position and/or orientation.
•Mouse (2D and 3D)
•Trackball, spaceball
•Joystick (2D and 3D)
•Tablet
•Virtual Reality Trackers
•Magnetic, Acoustic, Inertial,
Optical
Expanded by Jozef Goetz
Keyboard
• Text input
– List boxes, GUI
– CAD/CAM
– Modelling
• Hard coded
– Vertex locations are inserted into code
Expanded by Jozef Goetz
Scanners
• Image Scanners - Flatbed, etc.
– What type of data is returned?
Bitmap
• Laser Scanners - Deltasphere
– Emits a laser and does time of flight.
Returns 3D point
• Camera based - research
– Examine camera image(s) and try
to figure out vertices from them.
Expanded by Jozef Goetz
Computation Stage
Input
Computation
Output
• Now that we have a model of what we want to
draw, what goes on inside the computer to
generate the output?
Computation
Transformations
Rasterization
Expanded by Jozef Goetz
Computation Stage
Computation
Output
Model
Rasterization
Transformations
Transformed
Model
Expanded by Jozef Goetz
Expanded by Jozef Goetz
How do we store this?
We would like to allocate memory to hold
the results of the computation stage.
Expanded by Jozef Goetz
Framebuffer
Framebuffer - A block of memory, dedicated to
graphics output, that holds the contents of
what will be displayed.
Pixel (picture element) - one element of the
framebuffer, = each screen spot that can be
illuminated by the electron bean
Expanded by Jozef Goetz
Pixels and the Frame Buffer
• Pixels
– Squares of a uniform color on a grid
•
Frame buffer (FB)
– Pixel accumulator (memory)
•
Depth
– Number of bits used for a pixel
•
•
•
•
•
1 bit: 2 colors;
8 bit: 256 colors
True color has >= 24 bits
RGB (red, green, blue)
Rasterization (scan conversion)
– converting geometric primitives (lines, polygons) to
pixels. See next slide.
Expanded by Jozef Goetz
RGB Framebuffer
Image © P Hanrahan
Expanded by Jozef Goetz
Graphics Definitions
• Raster
– derived from TV systems for a row of pixels
– commonly referred to as a scanline
– does influence algorithms
• reducing memory requirements, parallelism, etc.
– is the derivation of rasterization, scan-line
algorithms
Expanded by Jozef Goetz
Raster Images
• 2D array of memory memory
• Pixels stores different things
– Intensity
• RGB color
• Depth
• Others...
• May be mapped to special HW
Expanded by Jozef Goetz
Expanded by Jozef Goetz
Raster pros and cons
•Disadvantages
•Requires screen-sized memory array
•Discrete spatial sampling (pixels)
•Convergence (varying angles of
approach distance of e-beam across
CRT face)
•Limit on practical size (< 40 inches)
•Spurious X-ray radiation
•Occupies a large volume
•Advantages
•Allows solids to be displayed
•Uses low-cost CRT H/W (TVs)
•Whole screen is constantly updated
•Bright light-emitting display
technology
Expanded by Jozef Goetz
Framebuffer
Q: How much memory do we need to allocate for the
framebuffer?
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
How many pixels are there?
How big is the framebuffer?
What is the largest image you can display?
Expanded by Jozef Goetz
Framebuffer in Memory
• If we want a framebuffer of 640 pixels by 480
pixles, we should allocate:
framebuffer = 640*480 bits
• How many bits should we allocate?
Q: What do more bits get you?
A: More values to be stored at each pixel.
Why would you want to store something
other than a 1 or 0?
Expanded by Jozef Goetz
Framebuffer bit depth
• How many colors does 1 bit get you?
• How many colors do 8 bits get you?
– Monochrome systems use this (green/gray scale)
• What bit depth would you want for your
framebuffer?
bit depth - number of bits allocated per pixel in a buffer
Expanded by Jozef Goetz
Framebuffer bit depths
• Remember, we are
asking how much
memory do we
allocate to store the
color at each pixel?
• Common answers:
– 16 and 32 bits
Expanded by Jozef Goetz
Bit depths
• 16 bits per pixel (high color)
– 5 bits for red, 5/6 bits for green, 5 bits for blue
– potential of 32 reds, 32/64 green, 32 blues
– total colors: 65536
• 32 bits per pixel (true color)
– 8 bits for red, green, blue, and alpha
– potential for 256 reds, greens, and blues
• total colors: 16777216
– more than the eye can distinguish
• Let’s look at Display Control Panel
Expanded by Jozef Goetz
Data Type Refresher
•
•
•
•
•
•
•
bit - a 0 or 1. Can represent 2 unique values
byte - 8 bits. 256 values
word - 32 bits. 4,294,967,296 values
int - 32 bits.
float - 32 bits
double - 64 bits
unsigned byte - 8 bits
Expanded by Jozef Goetz
Memory
unsigned byte framebuffer[640*480*3];
framebuffer
Expanded by Jozef Goetz
Colour Index Framebuffer
Image © P Hanrahan
Expanded by Jozef Goetz
Graphic Card Memory
• How much memory is on our graphic card?
– 640 * 480 * 32 bits = 1,228,800 bytes
– 1024 * 768 * 32 bits = 3,145,728 bytes
– 1600 * 1200 * 32 bits = 7,680,000 bytes
• Exc: How much memory is on your graphics
card?
– See SystemTools =>System Information
• Side note: Playstation 1 has 2 MB RAM.
• What is the TV resolution? See father slides.
Expanded by Jozef Goetz
Dithering
• Creating the illusion of new colors and shades by
varying the pattern of dots.
• E.g. Newspaper photographs are dithered.
• If you look closely, you can see that different shades of gray are
produced by varying the patterns of black and white dots.
• There are no gray dots at all.
– The more dither patterns that a device or program
supports, the more shades of gray it can represent.
• Note: dithering differs from gray scaling.
– In gray scaling, each individual dot can have a different
shade of gray.
Expanded by Jozef Goetz
Dithering
• Why does it work? Spatial integration. Using
the fact that our eyes usually blend (mix)
areas of high frequency.
• Why do you need it if you don’t have enough
bits?
– Eyes can detect 100 shades of a color. Banding
(uniting) occurs with fewer colors.
• Where do you see this?
– Printers and newspaper!
Expanded by Jozef Goetz
Black and White Dithering
Expanded by Jozef Goetz
Dithering
• Trading spatial resolution for intensity and
color depth.
– Sometimes call digital half-toning or halftones
• Increases the number of apparent colors than
are actually capable of being displayed
Expanded by Jozef Goetz
16 colors
256 colors
Expanded by Jozef Goetz
Output
Input
Computation
Output
We have an image (framebuffer or model), now
we want to show it.
• Display
– Vector
– Raster Scan
Expanded by Jozef Goetz
Output
• Cathode-Ray Tube (CRT)
– Electron beam steered by deflection plates to
strike and activate phosphor
– Only emits for milliseconds and needs to be
refreshed
• Refresh Rate
– Needs fast refresh to avoid flicker
– Interlacing displays odd and even rows
• Color Displays
– Triad of colored phosphors
– shadow mask ensures proper targeting
Expanded by Jozef Goetz
Hardcopy
• Printers (Resolution, color depth)
– Dot Matrix
• uses a head with 7 to 24 pins to strike a ribbon
(single or multiple color
– Ink Jet Printers
• fires small balls of colored ink
– Laser Printers
• powder adheres to positive charged paper p.68
– Pen Plotters
• similar to vector displays, “infinite” resolution.
Expanded by Jozef Goetz
Vector Displays
• Unlike CRTs, vector
displays have a single gun
that is controlled to draw
lines.
– Think of having a VERY
FAST drawing pen.
• Pros: Diagrams/only draw
what you need
• Cons: No fill objects/Slows
with complexity
Expanded by Jozef Goetz
The electron moves across a scan line,
the beam intensity is turned on and off
to create of illuminated spots
Expanded by Jozef Goetz
Framebuffer -> Monitor
• The values in the framebuffer are converted from
a digital (1s and 0s representation, the bits) to an
analog signal that goes out to the monitor.
• A video card’s RAMDAC performs this operation,
once per frame.
• This is done automatically (not controlled by your code), and
• the conversion can be done while writing to the framebuffer.
Expanded by Jozef Goetz
Expanded by Jozef Goetz
Images - Outline
•
•
•
•
•
•
•
•
Image Definition
File Formats
Internal Representation
Saving Images to File
Using Internal Images
Loading Images from File
Image processing is a huge field
Just introduce some key ideas today
Expanded by Jozef Goetz
Image - Definition
• An Image is generally a 2-Dimensional array of
pixels
– Usually in rectilinear coordinates
• Resolution is determined by the number of pixels
• Quality is determined by
– the compression or
– number of bits stored per pixel
• Various Formats are used for storage of images on
disk
• Different layouts are used to hold an image in
memory
Expanded by Jozef Goetz
Some Image Storage Formats
• GIF - Graphics Interchange Format Lossless
compression
• JPEG - Joint Photographic Experts Group various levels of lossy compression supported
• PPM - Portable Pixmap - raw raster bitmap
• PGM - Portable Greymap - raw raster bitmap
• TIF - Interchange Format - compression
supported
• PostScript - can embed a bitmap
• PDF - can embed compressed bitmap
• …and many other proprietary formats
Expanded by Jozef Goetz
Internal Image Representations
• Raw byte arrays – e.g. 3 bytes Red, Green and
Blue for each pixel
• Pixel values + Lookup tables
• Other representations using however many bits
per pixel we want
Expanded by Jozef Goetz
Image Quality Issues
• Screen resolution
• Color
• Blank space between the
pixels
• Intentional image
degradation
•
•
•
•
Brightness
Contrast
Refresh rate
Sensitivity of display to
viewing angle
Expanded by Jozef Goetz
Other meanings of resolution
• The human eye can resolve 30 cycles per
degree (20/20 Snellen acuity).
– The Snellen fractions, 20/20, 20/30, etc., are
measures of sharpness of sight.
• "Normal" vision is 20/20. The term 20/20 is used when
a person can clearly see an object from a distance of 20
feet that can be viewed by the average person with
normal vision at the same distance.
Expanded by Jozef Goetz
Color
• There are no commercially available small
pixel technologies that can individually
change color.
– Color is encoded by placing different-colored
pixels adjacent to each other.
– Field sequential color uses red, blue and green
liquid crystal shutters to change color in front of
a monochrome screen.
Expanded by Jozef Goetz
Cathode Ray Tubes (CRTs) p.38
•Heating element on the yolk.
•Phosphor coated screen
coils
•Electrons are boiled off the filament
and drawn to the focusing system.
•The electrons are
focused into a
beam and “shot”
down the cylinder.
•Electron beam steered by deflection
plates to strike and activate phosphor
• Only emits for milliseconds and
needs to be refreshed
•The deflection plates “aim” the
electrons to a specific position on the
screen.
Expanded by Jozef Goetz
p.38
Expanded by Jozef Goetz
Expanded by Jozef Goetz
CRT Phosphor Screen
• The screen is coated with
phosphor,
– 3 colors for a color monitor,
– 1 for monochrome.
• For a color monitor,
– three guns light up red,
green, or blue phosphors.
• Intensity is controlled by
the amount of time at a
specific phosphor location.
Expanded by Jozef Goetz
Expanded by Jozef Goetz
Color CRT
•Red, Green and Blue electron guns.
•Screen coated with phosphor triads.
G
•Each triad is composed of a red, blue
and green phosphor dot.
•Typically 2.3 to 2.5 triads per pixel.
R
B
G
B
G
R
G
R
B
B
G
FLUORESCENCE - Light emitted while the phosphor is being struck by
electrons.
PHOSPHORESCENCE - Light given off once the electron beam is
removed.
PERSISTENCE - Is the time from the removal of excitation to the moment
when phosphorescence has decayed
toGoetz
10% of the initial light output.
Expanded by Jozef
Raster Displays
• Cathode Ray Tubes (CRTs), most “tube”
monitors you see. Very common, but big and
bulky.
• Liquid Crystal Displays (LCDs), there are
two types transmissive (laptops, those snazzy
new flat panel monitors) and reflective (wrist
watches).
Expanded by Jozef Goetz
Interlacing (interleave)
• Derived from TV standard
– NTSC and PAL use interlacing
• Divides single frame in two fields
– Odd and even scan line separation
1, 3, 5, 7, …. and 2, 4, 6, 8,…..
Expanded by Jozef Goetz
Raster interlaced scanning
Expanded by Jozef Goetz
Beam Movement
scan line - one row on the screen
interlace vs. non-interlace - Each frame is either
drawn entirely, or as two consecutively drawn
fields that alternate horizontal scan lines.
vertical sync (vertical retrace) - the motion of the
beam moving from the bottom of the image to
the top, after it has drawn a frame.
refresh rate - how many frames are drawn per
second.
– Eye can see 24 frames per second. TV is 30 Hz,
monitors are at least 60 Hz.
Expanded by Jozef Goetz
• Refresh rate is important, but remember it is
different than your program’s update rate.
• Why is higher, better?
Expanded by Jozef Goetz
Video Formats
•
•
•
•
•
NTSC - 525x480, 30f/s, interlaced
PAL - 625x480, 25f/s, interlaced
VGA - 640x480, 60f/s, noninterlaced
SVGA – 800x600, 60f/s, noninterlaced
RGB - 3 independent video signals and
synchronization signal, vary in resolution and refresh
rate
• Time-multiplexed color - R,G,B one after another on
a single signal, vary in resolution and refresh rate
Expanded by Jozef Goetz
CRTs (cont.)
-’s:
• Strong electrical fields and high voltage
• Heavy, not flat
+’s:
• Very good resolution
Expanded by Jozef Goetz
Liquid Crystal Displays (LCDs)
• Also divided into pixels,
– but no electron gun firing at a screen,
• LCDs have cells (liquid crystal material) that
either allow light to flow through, or block it.
Expanded by Jozef Goetz
Expanded by Jozef Goetz
Liquid Crystal Displays
• Liquid crystal displays use small flat chips
which change their transparency properties
when a voltage is applied.
• LCD elements are arranged in an n x m array
called the LCD matrix
– level of voltage controls gray levels.
– LCDs elements do not emit light,
– use backlights behind the LCD matrix
Expanded by Jozef Goetz
LCDs (cont.)
• Color is obtained by placing filters in front of
each LCD element
– Usually black space between pixels to separate the
filters.
– Because of the physical nature of the LCD
matrix, it is difficult to make the individual LCD
pixels very small.
– Image quality dependent on viewing angle.
Expanded by Jozef Goetz
LCDs (cont.)
LCD resolution is often quoted as number of
color elements not number of RGB triads.
R
G
B
R
B
R
G
R
G
B
G
B
R
B
R
G
R
G
B
G
B
R
R
G
Example: 320 horizontal by 240 vertical elements = 76,800
elements
– Equivalent to 76,800/3 = 25,500 RGB pixels
"Pixel Resolution" is 185 by 139 (320/1.73, 240/1.73)
Expanded by Jozef Goetz
LCDs (cont.)
• Passive LCD screens
• Active LCD screens
– Cycle through each
element of the LCD
matrix applying the
voltage required for that
element.
– Once aligned with the
electric field the
molecules in the LCD
will hold their
alignment for a short
time
Expanded by Jozef Goetz
– Each element contains a
small transistor that
maintains the voltage
until the next refresh
cycle.
– +’s: Higher contrast and
much faster response
than passive LCD
Advantages of LCDs
+’s:
• Flat
• Lightweight
• Low power consumption
Expanded by Jozef Goetz
Flat-panel displays
•
1.
2.
•
Flat-panel displays falls into two categories:
emissive displays and
nonemissive displays.
The emissive displays (or emitters) are
devices that convert electrical energy into
light.
– Plasma panels,
– thin-film electroluminescent displays, and
– light-emitting diodes
are examples of emissive displays.
Expanded by Jozef Goetz
Plasma panels, also called gas-discharge displays,
are constructed by filling the region
between two glass plates with a mixture of gases
that usually includes neon.
Firing voltages applied to an intersecting
pair of horizontal and vertical conductors cause
the gas at the intersection of the two conductors to break down
into a glowing plasma of electrons and ions.
Picture definition is stored in a refresh buffer,
and the firing voltages are applied to refresh
the pixel positions (at the intersections of the conductors)
60 times per second
p.45
Expanded by Jozef Goetz
•Thin-film electroluminescent displays
are similar in construction to plasma panels.
•The difference is that the region between
the glass plates is filled with a phosphor,
such as zinc sulfide doped with manganese,
instead of a gas.
•When a sufficiently high voltage is applied
to a pair of crossing electrodes, the phosphor becomes
a conductor in the area of the intersection of the two electrodes.
p.45
Expanded by Jozef Goetz
Projection Displays
• Use bright CRT or LCD
screens to generate an
image which is sent
through an optical
system to focus on a
(usually) large screen.
Expanded by Jozef Goetz
Projector Technology
see http://electronics.howstuffworks.com/projection-tv.htm
• Two Basic Designs
– Transmittive projectors
• Shine light through the image-forming element
(CRT tube, LCD panel)
– Reflective projectors
• Bounce light off the image-forming element
• In both types of projectors,
• a lens collects the image from the image-forming
element,
• magnifies the image and
• focuses it onto a screen
Expanded by Jozef Goetz
Basic Projector Designs
(Images from Phillips Research)
Reflective Projection System
Transmittive Projection
System
Expanded by Jozef Goetz
Transmitive Projectors
CRT Based
• 1 color CRT tube (red, blue, green
phosphors) displays an image with
one projection lens.
• 1 black-and-white CRT with a
rapidly rotating color filter wheel
(red, blue, green filters) is placed
between the CRT tube and the
projection lens.
CRT-based projectors are usually
heavy and large compared to
other technologies
• 3 CRT tubes (red, blue, green) with
3 lenses project the images. The
lenses are aligned so that a single
color image appears on the screen.
Expanded by Jozef Goetz
Transmitive Projectors
• LCD Based
– Use a bright light to illuminate an LCD panel,
and a lens projects the image formed by the
LCD onto a screen.
+’s:
• Small, lightweight compared to CRT
based displays
Expanded by Jozef Goetz
Reflective Projectors
• In reflective projectors,
– the image is formed on a small, reflective chip.
• When light shines on the chip, the image is
reflected off it and through a projection lens
to the screen.
• Recent innovations in reflective technology
have been in the the following areas:
– Microelectromechanical systems (MEMS)
• Digital micromirror device (DMD, DLP)
• Grating light valve (GLV)
– Liquid crystal on silicon (LCOS)
Expanded by Jozef Goetz
Advantages/Disadvantages
of Projection Display
+’s:
• Very large screens can provide large FoV
Field of View and
• can be seen by several people simultaneously.
-’s:
• Image quality can be fuzzy and somewhat
dimmer than conventional displays.
• Sensitivity to ambient (surrounding) light.
• Delicate optical alignment.
Expanded by Jozef Goetz
Displays in Virtual Reality
• This method does not produce true 3D images,
– provide a 3D effect by presenting a different view to each
eye of an observer so that scenes do appear to have depth
• When we simultaneously look the two views merge
into a single image and
– we perceive a scene with depth.
• To produce a stereoscopic effect on a raster system
is to display each of the two views on alternate
refresh cycles.
– The screen is viewed through glasses, with each lens
designed to act as a rapidly alternating shutter that is
synchronized to block out one of the views
Expanded by Jozef Goetz
Displays in Virtual Reality
• Head-Mounted Displays (HMDs)
– The display and a position tracker are attached to
the user’s head
• Head-Tracked Displays (HTDs)
– Display is stationary,
– tracker tracks the user’s head relative to the
display.
– Example: CAVE, Workbench, Stereo monitor
Expanded by Jozef Goetz
2-6 Graphics Networks
• Multi-user environment and computer networks
are common elements in many graphics apps.
• Various resources
•
•
•
•
processors
printers
plotters
data files
can be distributed on a network and shared by
multiple users.
• A graphic monitor on a network is generally referred
as a graphics server.
• The computer on the network executing a graphic app
is called the client, and the output of the app is
displayed on a graphics server.
Expanded by Jozef Goetz
2-7 Graphics on the Internet
• The Word Wide Web WWW provides a hypertext
system that allows users to locate and view docs that
can contain
• text
• graphics
• audio
• Resources: graphics files are identified by Uniform
Resource Locater URL
– e.g. http://www.siggraph.org/s2005/
•
•
•
protocol: http or ftp
server: www.siggraph.org/s2005
location (directory) on the server: s2005
• the Hypertext Markup Language HML provides a
simple method for developing graphics on the
Internet
• has limited capabilities Expanded by Jozef Goetz
2-8 Graphics Software
• special-purpose packages
• for nonprogrammers who want to generate pictures,
graphs, or charts without worrying about the graphics
procedure that might be needed to produce it
• the interface to a package is typically a set of menus that
allows users to communicate with programs.
• examples are artist’s painting programs, business,
medical, and engineering CAD systems
Expanded by Jozef Goetz
2-8 Graphics Software
• general programming packages
• provides of graphics functions (CG API) that can be
used in C, C++, C# Java, or Fortran
– CG API provides a software interface between programming
language and the hardware
• basic functions include:
– specifying picture components: lines, polygons, spheres, and
other objects
– setting color values
– selecting views of a scene
– applying rotations or transformation
• Packages:
–
–
–
–
GL (Graphics Library)
OpenGL
VRML (Virtual-Reality Modeling Language)
Java 2D and 3D
Expanded by Jozef Goetz
2-8 Graphics Software
Other Graphics Packages:
– aimed at the specific apps: animation, virtual
reality, or graphics on the Internet
• Open Inventor a set of OORoutines for
describing a scene with calls to OpenGL
• Virtual-Reality Modeling Language (VRML)
– a subset of Open Inventor
•
•
•
•
Java 2D and 3D
Mathematica
MatLab
Maple etc.
Expanded by Jozef Goetz
Coordinate Representations
• To generate a picture using a package need to
give the geometric object description:
– location
– shapes of the objects
• e.g.
– a box is specified by the positions of its corners
(vertices)
– a sphere is defined by its center position and
radius
– general graphics packages require geometric
description tbs in a standard, right-handed,
Cartesian-coordinate reference frame.
Expanded by Jozef Goetz
Graphics Functions
p.71
• Graphics output primitives provide the basic
tools for constructing pictures:
–
–
–
–
–
–
–
–
points,
lines,
curved lines,
spheres,
cones,
cylinders,
filled color areas (usually polygons), and
shapes with arrays of color points
Expanded by Jozef Goetz
Graphics Functions
p. 71
• attributes
– properties of the output primitives
• describe how they are displayed
• includes:
–
–
–
–
color specifications,
line styles,
text styles,
area-filling patterns
• geometric transformation to change
– the size
– position
– orientation of the object
• modeling transformation used to
– construct scenes where object descriptions are given in
local coordinates
– e.g. packages for electrical circuits
Expanded by Jozef Goetz
Graphics Functions
p.17
• viewing transformations used to select
a view of the scene (the type of projection to be
used) on a video monitor.
– other routines are specifying its
–
–
–
–
position,
size,
structure
lighting conditions for 3D
• input devices used to control and process the data
flow from these interactive devices
• other housekeeping functions:
– clear a screen display
– select color
– initialize parameters
Expanded by Jozef Goetz
Software Standards
• Goal of standardized software is portability
• GKS - Graphical Kernel System 1984 adopted by ISO
(International Standard Organization) and ANSI ( American
National Standard Institute)
• PHIGS - Programmer’s Hierarchical Interactive Graphics
Standards, which is an extension of GKS
• GL (Graphics Library) - a set of routines for fast, real-time
rendering, was developed by SGI (Silicon Graphics, Inc.)
• OpenGL was developed as a hardware-independent version
of GL in 90s
– function definitions are language independent
– a language binding is defined for a particular language
• OpenGL bindings are available for C/C++, Ada and Fortran
• You can use OpenGL from C#.
Expanded by Jozef Goetz
Software Standards
• GDI – Graphics (or Graphical) Device Interface
http://en.wikipedia.org/wiki/GDI
– is one of the three core components or "subsystems" of Microsoft
– GDI is responsible for tasks such as drawing lines and curves,
rendering fonts and handling palettes.
• It is not directly responsible for drawing windows, menus, etc.: that task
is reserved for the user subsystem.
– Simple games which do not require fast graphics rendering, such as
Freecell or Minesweeper, use GDI.
– -’s: GDI cannot animate properly (no notion of synchronizing with the
framebuffer) and lacks rasterization for 3D.
• DirectX - (originally called "Game SDK")
http://en.wikipedia.org/wiki/DirectX
– is a collection of APIs for easily handling tasks related to game
programming on Microsoft Windows. It is most widely used in the
development of computer games for Windows. The DirectX SDK is
available free from Microsoft.
– Modern games use DirectX, which gives programmers access to more
hardware capabilities.
Expanded by Jozef Goetz
Software Standards
• Java graphics API’s
– Standard AWT Graphics class [2D]
– Java Platform 2 Graphics2D class [2D]
– Java3D [PC only – uses OpenGL or Direct3D]
• MacOS Quickdraw [2D], Apple’s Quickdraw3D
[3D]
• X-window’s Xlib [2D]
• Very few “standards” have lasted long
– Quickdraw3D, GKS, PHIGS are defunct (dead)
– Java3D struggling for acceptance
• OpenGL is the only successful multiplatform 3D
graphics API
Expanded by Jozef Goetz
What is OpenGL?
• http://www.opengl.org/about/overview.html
• OpenGL is the most widely adopted, cross-platform
standard for 3D rendering and 3D hardware acceleration.
• The software runtime library ships with
–
–
–
–
all Windows,
MacOS,
Linux and
Unix systems.
• Graphics API
– Created in 1992
– large & efficient collection of device-independent functions for
creating computer graphics (CG) displays
• therefore no input/output routines are included
– input/output routines are available from auxiliary libraries
– written in C or C++
• Open Standard
• Uses a state machine
Expanded by Jozef Goetz
Can we use OpenGL in?
Expanded by Jozef Goetz
OpenGL
• OpenGL is strictly defined as “a
software interface to graphics
hardware”.
• It is a 3D graphics and modeling library
• Developed by SGI (Silicon Graphics, Inc.)
Expanded by Jozef Goetz
OpenGL Library Organization
GLU
Open GL Utility
OpenGL
Application
Program
Frame
Buffer
GL
core library
GLUT
Xlib,Xtk
Utility Toolkit
GLX
X Windows
Expanded by Jozef Goetz
Can use
•gl.h and glu.h or
•glut.h or
•glx.h
from http://www.opengl.org/resources/libraries/glut.html
GLUT - The OpenGL Utility Toolkit
• GLUT (pronounced like the glut in gluttony) is the
OpenGL Utility Toolkit, a window system
independent toolkit for writing OpenGL programs.
– It implements a simple windowing application
programming interface (API) for OpenGL.
– GLUT makes it considerably easier to learn about and
explore OpenGL programming.
– GLUT provides a portable API so you can write a single
OpenGL program that works across all PC and workstation
OS platforms.
• GLUT is designed for constructing small to medium
sized OpenGL programs.
– While GLUT is well-suited to learning OpenGL and
developing simple OpenGL applications,
– GLUT is not a full-featured toolkit so large applications requiring
sophisticated user interfaces are better off using native window system
Expanded by
Jozef Goetz
toolkits. GLUT is simple, easy,
and
small.
from http://www.opengl.org/resources/libraries/glut.html
• The GLUT library has both C, C++ (same as C),
FORTRAN, and Ada programming bindings.
• The GLUT source code distribution is portable to
nearly all OpenGL implementations and platforms.
• GLUT is not open source.
– Mark Kilgard maintains the copyright.
– There are a number of newer and open source alternatives.
– there are numerous other Toolkits and interface libraries built
on top of OpenGL as compliments or modern replacements to
GLUT.
• The current version of the GLUT API is 3.
The current source code distribution is GLUT 3.7.
– Additional releases of the library are not anticipated.
•
Expanded by Jozef Goetz
GLUT source code distribution
•
http://www.opengl.org/resources/libraries/glut/glut_downloads.html
• GLUT is distributed in source code form; compiled libraries for Win32 are
also available. The current version, 3.7
• The OpenGL Utility Toolkit (GLUT), originally written by Mark Kilgard,
ported to Win32 (Windows 95,98,Me,NT,2000,XP) by Nate Robins.
•
glut-3.7.6-bin.zip (117 KB)
GLUT for Win32 dll, lib and header file (everything you need to get started
programming with GLUT).
glut-3.7.6-src.zip (4.76 MB)
GLUT source code distribution (including a whole slew of great example
programs + data).
Documentation for the GLUT API is available in HTML, Postscript and
PDF formats. For general information about GLUT, see opengl.org's GLUT
page or opengl.org's GLUT FAQ. or sgi's GLUT ftp.
Expanded by Jozef Goetz
OpenGL Installation procedure
To run Computer Graphics programs with OpenGL we need to include only one directive
#include <GL/glut.h>
So the environment has to have all files distributed and registered.
In order to do that we need:
1: Download
glut-3.7.6-src.zip (4.76 MB)
- GLUT source code distribution (including a whole slew of great example programs + data).
2. Unzip it
Microsoft Developer Studio 6 workspace and project files have been included in the source code
distribution. Additional workspace files have been included in the programs, test
and lib directories to build the programs, tests and libraries respectively.
3. COMPILING/INSTALLATION (no more than 5 min):
To build the glut dll:
a. First, open Microsoft Developer Studio.
b. Then, select File -> Open Workspace and find the glut.dsw file in the file dialog and doubleclick on it.
c: Finally, select Build -> Build glut32.dll.
When the build is finished, it will copy:
glut32.dll to %WinDir%\System,
in my laptop case was C:\Windows/System32;
glut32.lib to $(MSDevDir)\..\..\VC98\lib, and in my laptop case was
C:\Program Files\Microsoft Visual Studio\VC98\Lib;
glut.h to $(MSDevDir)\..\..\VC98\include\GL. in my laptop case was
C:\Program Files\Microsoft Visual Studio\VC98\Include\GL
Expanded by Jozef Goetz
Capabilities of OpenGL
•
•
•
•
•
•
•
Texture & Environment Mapping
Lighting
Ray Tracing
Bump Mapping (used to add detail)
Selection and Feedback
Display List
Shadows
Expanded by Jozef Goetz
Color
• Various color spaces provide ways to
specify colors in term of components:
– red, green, blue
– hue, saturation,value
– different output devices display different
subsets of the perceptible colors
Expanded by Jozef Goetz
RGB Color
Conceptually,
• there are separate frame buffers for red,
green, and blue
• Each pixel has separate red, green, and blue
components that corresponding to location in
memory
• Typical system might be a 1028x1024 array of
pixels,
• each pixel might consist of 24 bits (3 bytes)
Expanded by Jozef Goetz
RGB Color (cont)
Example
• in a 24 bits example, there are 224 possible
colors which sometime referred to as 16M
colors
• How much framebuffer we need for a
1280x1024 pixels?
Expanded by Jozef Goetz
Color in OpenGL
• glColor3f(1.0,0.0,0.0)
• this present a red color
• 3f = use a RGB model, and the value of the
component is float in C.
Expanded by Jozef Goetz
Color in OpenGL
• Four-color(RGBA) system
• A is called alpha channel,
– stored in the frame buffer as are the RGB value
• The alpha value will be treated by OpenGL as
an opacity = 1.0 or transparency = 0.0
• glClearColor(1.0, 1.0, 1.0, 1.0)
– = solid and white
Expanded by Jozef Goetz
Indexed Color
• What happen if the size of frame buffer is not
enough, relatively to a spatial resolution given?
• Many systems have frame buffers that are
limited in depth.
• We can select colors by interpreting our
limited-depth pixels as indices rather than as
color values
Expanded by Jozef Goetz
Color-lookup Table
• Suppose frame buffer has k bits / pixel
• Each pixel value or index is an integer
k
between 0 and 2 -1
• Suppose we can display each color with an
accuracy of m bits
– e.g. m = 8, we can choose 256 colors out of 16M
(224 possible )
Expanded by Jozef Goetz
Color-lookup Table
Input
0
1
2
Red
0
m
2 -1
0
Green
0
0
m
2 -1
Blue
0
0
0
k
2 -1
m bits
m bits
Expanded by Jozef Goetz
m bits
Indexed Color
Color
Lookup Table
A
Color
Lookup Table
Red
Green
Blue
Color
Lookup Table
Expanded by Jozef Goetz
A
Colour Index Framebuffer
Image © P Hanrahan
Expanded by Jozef Goetz
The line in the Display Window
Expanded by Jozef Goetz
Display a 2D line segment
#include <GL/glut.h>
void init (void)
{
glClearColor (1.0, 1.0, 1.0, 0.0);
// Set display-window (DW) color to white; R = G = B = 1.0 = white; R = G = B = 0.0 = black
// glClearColor (R, G, B, resulting color for 2 overlapping objects if 0.0 = transparent object );
glMatrixMode (GL_PROJECTION);
// Set projection parameters through the 3D even we want to produce a 2D picture.
gluOrtho2D (0.0, 200.0, 0.0, 150.0);
// gluOrtho2D (min_x, max_x, min_y, max_y); - defines the coordinate reference frame
// within the DW to be ( 0.0, 0.0) at the lower-left corner of the DW
// & (200.00, 150.00) at the upper-right window corner
}
void lineSegment (void)
// callback function: it is called each time when certain action occurs e.g. redisplaying window
{
glClear (GL_COLOR_BUFFER_BIT); // Clear display window according to the values indicated in glClearColor function.
glColor3f (1.0, 0.0, 0.0);
glBegin (GL_LINES);
glVertex2i (180, 15);
glVertex2i (10, 145);
glEnd ( );
// Set line segment color to RGB color components (red) using floating-point (f) values.
// symbolic constant argument GL_LINES, GL_POINTS, etc.
// Specify line-segment geometry, Cartesian endpoint coordinates.
// a suffix 2, 3, or 4 – the dimensionality ; data type: i - integer, s – short, f – float, d - double
glFlush ( );
// Force to execute all OpenGL functions which are stored in buffers in different locations.
// = Process all OpenGL routines as quickly as possible.
}
void main (int argc, char** argv)
{
glutInit (&argc, argv);
// Initialize GLUT.
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // Set display mode: a single refresh buffer for DW and RGB color.
glutInitWindowPosition (50, 100);
// Set top-left DW position, video screen (0, 0) is at the upper-left corner of the screen.
glutInitWindowSize (400, 300);
// Specify DW width and height from (50, 100);
glutCreateWindow ("An Example OpenGL Program"); // Create DW with the header label ("An Example OpenGL Program");
init ( );
glutDisplayFunc (lineSegment);
glutMainLoop ( );
}
// Execute initialization procedure.
// register callback function lineSegment (void), send graphics to DW,
Expanded by Jozef Goetz
// Display everything
and wait in the loop from input from the input device or other events.
Exercises
0. Run the line segment program with
different combinations of color by
changing parameters in
glColor3f (1.0, 0.0, 0.0);
// Set line segment color to RGB color components (red)
// using floating-point (f) values.
Expanded by Jozef Goetz
1a. + 2a.
Exercises
1a.Change the coordinates in:
glutInitWindowPosition (50, 100); // Set top-left DW position, video screen (0, 0) is at the upperleft corner of the screen.
glutInitWindowSize (400, 300); // Specify DW width and height from (50, 100);
to
original
glutInitWindowPosition (50, 100);
glutInitWindowSize (10, 300);
now1.a
and watch the impact on the display window (DW)
1b. Apply your own coordinates values
1c. Set up the previous values
2a. Change the coordinates in:
gluOrtho2D (0.0, 200.0, 0.0, 150.0); // gluOrtho2D (min_x, max_x, min_y, max_y); - defines the
// coordinate world reference frame
to
gluOrtho2D (70.0, 200.0, 71.0, 150.0);
and watch the impact on the display window
(is something cut, why?)
You had glVertex2i (180, 15); glVertex2i (10, 145);
reduced (?) to glVertex2i (180, 71); glVertex2i (70, 145);
2b. Apply your own coordinates values
2c. Set up the previous values
Expanded by Jozef Goetz
Get 1a. || 2a.
Exercises
3a. Change the coordinates in:
gluOrtho2D (0.0, 200.0, 0.0, 150.0); // gluOrtho2D (min_x, max_x, min_y, max_y); - defines the
// coordinate reference frame
to
gluOrtho2D (0.0, 200.0, 70.0, 150.0);
and watch the impact on the display window
3b. Apply your own coordinates values and draw a conclusion
3c. Set up the previous values
Output: original was
Now:
Conclusion:
1. Only those parts of primitive within the DW coordinate range will be shown
2. The window size remains the sameExpanded
b/c byglutInitWindowSize
(400, 300);
Jozef Goetz
Exercises
4a. Change the coordinates in:
glVertex2i (180, 15); // Specify line-segment
originalgeometry,
glVertex2i (10, 145);
to
glVertex2i (80, 15);
glVertex2i (0, 145);
and watch the impact in the display window.
4b. Change to
glVertex2i (80, 145);
glVertex2i (0, 195);
Apply your own boundary coordinates
Values. Explain the graph.
Expanded by Jozef Goetz
4a. now
4b. now
Exercises
4c. Change the coordinates in:
glVertex2i (180, 15);,
glVertex2i (10, 145);
to
glVertex2i (80, 145);
glVertex2i (0, 145);
Explain the graph.
original
4b. now
Expanded by Jozef Goetz
4c. now
Exercises
4d. Change the coordinates in:
glVertex2i (180, 15); // Specify line-segment
geometry,
original
glVertex2i (10, 145);
to
glVertex2i (195, 145);
glVertex2i (5, 5);
4b. now
Apply your own boundary coordinates values
4e. Set up the previous values
• When we set up the geometry describing a picture, all
positions for the OpenGL primitives must be given in
absolute coordinates with respect to the frame defined
in gluOrtho2D ()
Expanded by Jozef Goetz