CSC480: Computer Graphics

Dr. Yaser Khamayseh Assistant Professor Computer Science Dept

Jordan University of Science and Technology .

Topics to Cover

• Introduction to Computer Graphics: definition, history, applications, hardware, and software • A guide to OpenGL • Algorithms for drawing 2D primitives: lines, circles, ellipses, filling, clipping, generating characters • Geometrical 2D and 3D transformation • Viewing in 3D: viewing 3D objects on 2D computer monitor • Color and lighting • Advanced topics

`ˆÌi`ÊÜˆÌ ÊÌ iÊ`i“œÊÛiÀȜ˜ÊœvÊ ˜vˆÝÊ*ÀœÊ* Ê `ˆÌœÀÊ

/œÊÀi“œÛiÊÌ ˆÃʘœÌˆVi]ÊۈÈÌ\Ê ÜÜÜ°ˆVi˜ˆ°Vœ“É՘œVŽ° ̓ Introduction

What is Computer Graphics? Applications History Display Technologies Graphics Library

What is Computer Graphics? • Computer Graphics is concerned with producing images using a computer – Modeling: Create and represent the geometry of objects in the 3D world – Rendering: Generate 2D images of the objects – Animation: Describe how objects move

Modeling

• Take the real and turn it into a virtual • Explain the real world or fantastic objects using mathematics • If the image does not exist in real life, a blueprint is drawn by an artist

A wire frame is the simplest form of model

Wireframe Model

Rendering

• Draw the image on 2D screen • Color • Lighting Wireframe Model • Shading • Surface texture • Shadows • Reflection and transparency • Intersection, surface- Final Render removal hiding

Animation

• Control the movements of objects • Laws of physics • Biomechanics, • Special effects

In Comparison to Image Processing • Image Processing: analysis of scenes, or the reconstruction of 2D or 3D objects from their images – Image enhancement: Eliminate noise or enhance contrast in an image – Pattern recognition: Detect and classify patterns in an image – Computer vision: Recognize and reconstruct a 3D model of a scene from several images

Computer Graphics and Image Processing

• The main task in computer graphics is to create pictures and images to synthesize them on the basis of some description, or model, in a computer. • The main task in image processing, on the other hand, is – to improve or alter images that were created elsewhere, perhaps digitized from photographs or captured by a video recorder.

– Processing can remove "specks" of noise from an image, enhance the contrast of the image, sharpen its edges, and fix its colors. – Software routines can be used to search for certain features in an image and highlight them to make them more noticeable or understandable.

Output

Image Description

Image Processing Image Pattern Image Recognition, Computer Vision Input

Description Computer Other Data Processing Graphics

Image Enhancement Example

Graphics Applications: User Interfaces

Graphics Applications: Cinema, Games

Pixar: Monster’s Inc.

Graphics Applications: Medical Visualization

MIT: Image-Guided Surgery Project The Visible Human Project

Graphics Applications: Computer- Added Design

` Graphics Applications: Virtual Reality

Elumens’ VisionStation CMU CUBE

History (1/14)

• The term “Computer Graphics” was coined in 1960 by William Fetter to describe new design method he was pursuing at Boeing – Widely reproduced images were created on a plotter exploring cockpit design using a 3D model of a human body

“Perhaps the best way to define computer graphics is to find out what it is not. It is not a machine. It is not a computer, nor a group of computer programs. It is not the know-how of a graphic designer, a programmer, a writer, a motion picture specialist, or a reproduction specialist. Computer graphics is all these – a consciously managed and documented technology directed toward communicating information accurately and descriptively.” Computer Graphics , by William A. Fetter, 1966

´ History (2/14)

1885: Cathod Ray Tube

History (3/14) Whirlwind Computer (MIT, 1950): input via keypunch, output via printer/plotter, both in batch

Cool facts : Whirlwind, built in the early 50’s at MIT, cost $4.5 million and could perform 40,000 additions/second. Mac 512K, list price $3,195 in 1984, could do 500,000. Today, commodity PCs perform approximately one billion operations/second

Sketchpad (Sutherland, MIT, 1963): first truly interactive graphics system, using a CRT monitor, light pen, and function-key pad first CAD system (IBM, 1959)

^ History (5/14)

1966: Ralph Baer creates the 1st consumer CG product: Odyssey Pinball

History (6/14)

1967 • GE introduces first full color real time flight simulator for NASA

History (7/14)

1973: Michael Crichton’s “Westworld” uses 2D graphics • First time computer is used for image manipulation. • Featured scenes that showed audiences the world viewed by the eye circuitry of a synthetic human (played by a very real Yul Brenner) in a future Western theme park. This effect was achieved with 2D computer graphics tools mostly derived from image processing techniques.

History (8/14)

1974: Intel developed the 8080 processor.

1975: Bill Gates started

1976: Steve Jobs and Steve Wozniak started Apple.

History (9/14)

1977: Academy of Motion Pictures Art and Sciences introduced VISUAL EFFECT category for Oscars.

Winner: Star Wars

History (10/14)

1981 • IBM introduces the first IBM PC (16 bit 8088 chip)

History (11/14)

1983: First Coke Polar Bears Commercial

History (12/14) 1985: The Last Starfighter is the first live action feature film with realistic computer animation of highly detailed models.

1989: The Abyss is the first movie to include convincing 3D character animation.

History (13/14)

1990: Windows 3.0 ships

1994: PlayStation and N64 released

2000: PlayStation 2

2002: MS XBox

History (14/14)

2002 • Academy of Motion Pictures introduced a category for BEST ANIMATED FEATURE.

• Winner: Shrek

Uses of Computer Graphics

We can conclude that the uses of Computer Graphics in general are

Display of Information, Design, Simulation (scientific visualization, entertainment, education/training), User Interface (Windows OS, Mac, X, Next etc.).

Computer Graphics is used in specific areas :

Business/Office automation (Desktop publishing., E-mail., Hypermedia. ),

Graphs (Business., Math., Modeling.),

Image Processing (Satellite, Medical., Weather, Police.),

CAD/CAM (Industry, Electrical Circuit Design, Landscape, Buildings, Materials.),

Art and Design (Graphic Design., Presentation, Television, Advertising.),

Animation (Games, Virtual Reality, Cartoons, Nuclear/Chemical Reactions.),

Cartography (Geology, Oceanography , GIS etc.) Scientific Analysis and Visualization.

Output Technologies

Raster Display Vector Display

1963 1972 1980’s timeline Xerox PARC

Vector Display (1/2)

Vector Display (2/4) • Refresh buffer stores the computer-produced display list or display program; it contains: – point- and line-plotting commands – character-plotting commands • The beam from CRT is deflected from endpoint to endpoint.

Vector Displys (3/4) video displays called "vector," "random-scan," or "calligraphic" displays that produce line drawings. These devices specially designed to sweep an electronic beam from point to point across the face of a cathode-ray tube, leaving a glowing trail. Since each line segment to be displayed ( two endpoints and perhaps a color), vector displays can draw a vector picture very rapidly (hundreds of thousands of vectors per second).

` Disadvantages of Vector Displays: • Vector displays, cannot show smoothly-shaded regions or scanned images. Region filling is usually simulated by cross-hatching with different line patterns,

• Today raster displays have largely replaced vector displays, except in very specialized applications.

Raster Display (1/20)

2 - Raster Displays The most familiar raster displays are the video monitor connected to personal computers and workstations, and the flat-panel display common to portable personal computers.

Other common displays produce hard copy of an image: the laser printer, dot matrix printer, ink-jet plotter, and film recorder.

´ Raster Display (2/20)

• Raster is a matrix of representing the entire screen area. At each , the beam’s intensity reflects the pixel’s intensity • The screen is scanned sequentially from left to right, top to bottom. Scan line

Horizontal Vertical retrace retrace

Vector vs. Raster

^ Pros. and Cons. of Raster

• Advantage: – Lower cost CRT technologies – The ability to display areas filled with solid colors or patterns, which is essential for realistic images of 3D objects

• Disadvantage: – Aliasing: the image is not smooth – Computationally demanding for drawing primitives, thus not good for wireframes

Raster Image • Pixels : A "pixel" (picture element) is a relative unit and has no absolute size. If you divide a picture into any number of square samples of any size, you could call these samples as pixels. It doesn't matter what size, only that they are all the same size.

A raster image is stored in a computer as an array of numerical values. The array is thought of as being rectangular, with a certain number of rows and a certain num•ber of columns. Each numerical value represents the value of the pixel stored there. The array as a whole is often called a "pixel map." The term "" is also used

• Raster images also frequently contain images of straight lines. A line is created in an image by setting the proper pixels to the line's color. • But quite a bit of computation may be required to determine the sequence of pixels that "best fit" the ideal line between two given endpoints.

Pixel depth: • Two bits per pixel produce 4 gray levels • four bits per pixel produce 16 gray levels • eight bits per pixel produce 256 gray levels

Raster Displays All raster displays have a built-in coordinate system that associates a given pixel in an image with a given physical position on the display surface. The graphics program is stored in system memory and is executed by the CPU. The program computes appropriate values for each pixel in the desired image and loads the values into the frame buffer. (using building tools that write the "correct" pixel values into the frame buffer.)

A "scan controller" takes care of the actual display process, running independently. The scan controller causes the frame buffer to "send" each pixel through a converter to the appropriate physical spot on the display surface.

The converter takes a pixel value such as 01001011 and converts it to the corresponding quantity that produces a spot of color on the display.

The Scanning Process

• The main issue is how each pixel value in the frame buffer is "sent" to the right place on the display surface.

• For address (136, 252), the value mem[136][252] is converted to a corresponding intensity or color in the conversion circuit (converter), and that intensity or color is sent to the proper physical position by (scan controller), (136, 252), on the display surface.

• In some devices, as CRT. The CRT image must be refreshed rapidly (typically, 60 times a second) to prevent disturbing flicker.

RGB color

• Each color component is stored separately in the frame buffer • Usually 8 bits per component in buffer • Note in glColor3f the color values range from 0.0 (none) to 1.0 (all), whereas in glColor3ub the values range from 0 to 255

46 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Indexed Color

• Colors are indices into tables of RGB values • Requires less memory – indices usually 8 bits – not as important now • Memory inexpensive • Need more colors for shading

47 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Color Raster Images • Each pixel in a color image has a "color value," a numerical value that somehow represents a color. The most common is to describe a color as a combination of amounts of Red, Green, and Blue light. • (23,14,51)prescribes the intensities of the red, green, and blue components. • The of the pixel: Each value in the (red, green, blue) triple has a certain number of bits, and the color depth is the sum of these values. For 3 bits color depth , there are eight possible colors, as tabulated in Figure 1.31. As expected, equal amounts of red, green, and blue, (1,1,1), produce white.

Any color can be constructed by "adding" certain amounts of 3 primary colors.

C = rR + gG + bB

where r, g and b indicate the "amounts" of each .

Many images have a color depth of eight. Each pixel then has one of 256 possible colors.

A 24 bit system, True-Color systems are common. Each color component given 8 bits

Color Depth = 6

The red, green, and blue components of a pixel each use a pair of bits. The pairs are fed to three digital-to-analog converters (DACs), which convert logical values like 01 into actual voltages. •The correspondence between Input Voltage/brightness

digital input values and output 00 0 *Max voltages is shown in Table, 01 0.333 * Max where Max is the largest 10 0.666 * Max voltage level the DAC can produce. 11 1 *Max

Color Depth = 6

• The three voltage levels drive three "guns" inside the CRT, which in turn excite three electron beams with intensities proportional to the voltages.

The deflection coils divert the three beams so that they stimulate three tiny phosphor dots at the proper place, (x, y).

• Assuming Color Depth = 6 bits Color video displays • Thus, the composite dot can be made to glow in a total of 22 X 22 X 22 = 4 X 4 X 4 = 64 different colors. • Some systems have a frame buffer that supports 24 bits color depth. Each of the DACs has eight input bits, so there are 256 levels of red, 256 of green, and 256 of blue, for a total of 16 million colors. • The CRT image must be refreshed rapidly (typically, 60 times a second) to prevent disturbing flicker.

There are monochrome video displays, which display a single color in different intensities. A single DAC converts pixel values in the frame buffer to voltage levels, which drive a single electron-beam gun. The CRT has only one type of phosphor, so it can produce various intensities of only one color. • Note that 6 bits in in the frame buffer for monochrome video displays 26 = 64 levels of gray.

Indexed Color and the Lookup Table

Figure 1.40

(Why are there exactly 64 entries in this LUT?)

The 6 bits stored in each pixel. These bits are used as an index into a table of 64 values, say, LUT [ 0 ] ... LUT [63]. For instance, if a pixel value is 39, the values stored in LUT [39] are used to drive the DACs. As shown in the figure, LUT [39] contains the 15-bit value 01010 11001 10010 Five of these bits (01010) are routed to drive the "red DAC," 5 others drive the "green DAC," and the last 5 drive the "blue DAC." Each of the LUT [ ] entries can be set under program control. For example, the instruction setPalette(39, 17, 25, 4) ; would set the value in LUT[39] to the 15-bit quantity 1000111001 00100 (since 17 is 10001 in binary, 25 is 11001, and 4 is 00100).

• Example: set the pixel at x = 479 and y= 532 with value 39 drawDot(479, 532, 39) ; Each time the frame buffer is "scanned out" to the display, this pixel is read as the value 39, which causes the value stored in LUT[39] to be sent to the DACs.

How many possible color could be used in the system of Figure 1.40? In the system of Figure 1.40, each entry of the LUT consists of 15 bits, so each color can be set to one of 215 = 32K = 32,768 possible colors.

The set of 215 possible colors that the system is capable of displaying is called its , so we say that this display "has a palette of 32K colors." Therefore, this system can display a maximum of 26 = 64 different colors at one time selected from 215 = 32K = 32,768 possible colors

` • The contents of the LUT are not changed in the middle of a scan-out of the image, so one whole scan-out uses a fixed set of 26 = 64 palette colors.

• Usually, the contents of the LUT remain fixed for many scanouts, although a program can change the contents of a small LUT between two successive scan-outs.

• In more general terms, suppose that a raster display system has a color depth of b bits and that each LUT entry is w bits wide. Then

– The system can display 2w colors, any 2b at one time.

• EXAMPLEs • 1. A system with b = 8 bit planes and an LUT width w = 12 can display 4096 colors, any 256 of them at a time.

• 2. A system with b = 8 bit planes and an LUT width w = 24 can display 224 = 16,777,216 colors, any 256 at a time.

• 3. If b = 12 and w = 18, the system can display 256K = 262,144 colors, 4,096 at a time

´ To compare the costs of two systems, one with a LUT (pseudo color system) and one without a LUT (true color system)

Figure 1.41 shows an example of two l,024-by-l,280-pixel displays (so that each of them supports about 1.3 million pixels).

Both systems allow colors to be defined with a precision of 24 bits, often called "true color."

1024 * 1280 * 24 = ~ 4MByte expensive (frame buffer needs ~ 4Mbyte)

24 bits/pixel

1.3 million pixels

Figure 1.41

1024 * 1280 * 8 = ~ 1MByte LUT requires 256 * 3 = 768 inexpensive (frame buffer needs ~ IMbyte)

^