13
Fourth Edition Donald Hearn M. Pauline Baker School of Informatics, Computer Science Department, and Pervasive Technology Labs at Indiana University Indiana University—Purdue University Indianapolis Warren R. Carithers Department of Computer Science Rochester Institute of Technology PEARSON Boston Columbus Indianapolis New York San Francisco Upper Saddle River Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo

Warren R. Carithers

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Fourth Edition

Donald Hearn

M. Pauline Baker

School of Informatics, ComputerScience Department, and

Pervasive Technology Labs at

Indiana UniversityIndiana University—Purdue

University Indianapolis

Warren R. Carithers

Department of Computer Science

Rochester Institute of Technology

PEARSON

Boston Columbus Indianapolis New York San Francisco Upper Saddle River

Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto

Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo

Contents

Preface 19

About the Authors 24

3-1

3-2

3-3

3-4

3-5

A Survey of Computer

Graphics 25

1-1 Graphs and Charts 26 2-5

1-2 Computer-Aided Design 26 2-6

1-3 Virtual-Reality Environments 28 2-7

1-4 Data Visualizations 28 2-8

1-5 Education and Training 29

1-6 Computer Art 29

1-7 Entertainment 30

1-8 Image Processing 31

1-9 Graphical User Interfaces 31

1-10 Summary 32

Computer GraphicsHardware 33

2-1 Video Display Devices 34

Refresh Cathode-Ray Tubes 34

Raster-Scan Displays 37

Random-Scan Displays 39

Color CRT Monitors 40

Flat-Panel Displays 42

Three-Dimensional Viewing Devices 443_g

Stereoscopic and Virtual-Reality Systems 45

2-2 Raster-Scan Systems 46

Video Controller 46

Raster-Scan Display Processor 48

2-3 Graphics Workstations and Viewing 4-1

Systems 49

2-4 Input Devices 50

Keyboards, Button Boxes, and Dials 50

Mouse Devices 50 4-2

Trackballs and Spaceballs 51

Joysticks 51

Data Gloves 52

Digitizers 52

Image Scanners 53

Touch Panels 53

Light Pens 54

Voice Systems 54

Hard-Copy Devices 54

Graphics Networks 56

Graphics on the Internet 56

Summary 57

Computer GraphicsSoftware 59

Coordinate Representations 60

Graphics Functions 61

Software Standards 62

Other Graphics Packages 63

Introduction to OpenGL 64

Basic OpenGL Syntax 64

Related Libraries 64

Header Files 65

Display-Window Management UsingGLUT 66

A Complete OpenGL Program 67

Error Handling in OpenGL 71

Summary 72

Graphics Output Primitives 75

Coordinate Reference Frames 76

Screen Coordinates 76

Absolute and Relative Coordinate

Specifications 77

Specifying A Two-Dimensional World-

Coordinate Reference Frame

in OpenGL 78

8 Contents

4-3 OpenGL Point Functions 79

4-4 OpenGL Line Functions 81

4-5 OpenGL Curve Functions 82

4-6 Fill-Area Primitives 83

4-7 Polygon Fill Areas 84

Polygon Classifications 85

Identifying Concave Polygons 85

Splitting Concave Polygons 86

Splitting a Convex Polygon into a Set

ofTriangles 87

Inside-Outside Tests 87

Polygon Tables 90

Plane Equations 91

Front and Back Polygon Faces 92

4-8 OpenGL Polygon Fill-Area Functions 94

4-9 OpenGL Vertex Arrays 100

4-10 Pixel-Array Primitives 102

4-11 OpenGL Pixel-Array Functions 103

OpenGL Bitmap Function 103

OpenGL Pixmap Function 105

OpenGL Raster Operations 106

4-12 Character Primitives 107

4-13 OpenGL Character Functions 109

4-14 Picture Partitioning 110

4-15 OpenGL Display Lists 111

Creating and Naming an OpenGL DisplayList 111

Executing OpenGL Display Lists 112

Deleting OpenGL Display Lists 113

4-16 OpenGL Display-Window ReshapeFunction 113

4-17 Summary 116

Attributes of GraphicsPrimitives

5-1 OpenGL State Variables 130

5-2 Color and Grayscale 130

RGB Color Components 130

Color Tables 131

Grayscale 132

Other Color Parameters 133

5-3 OpenGL Color Functions 133

The OpenGL RGB and RGBA ColorModes 133

129

OpenGL Color-Index Mode 134

OpenGL Color Blending 135

OpenGL Color Arrays 136

Other OpenGL Color Functions 138

5-4 Point Attributes 139

5-5 OpenGL Point-Attribute

Functions 139

5-6 Line Attributes 139

Line Width 139

Line Style 140

Pen and Brush Options 140

5-7 OpenGL Line-Attribute

Functions 141

OpenGL Line-Width Function 141

OpenGL Line-Style Function 141

Other OpenGL Line Effects 143

5-8 Curve Attributes 143

5-9 Fill-Area Attributes 144

Fill Styles 144

Color-Blended Fill Regions 145

5-10 OpenGL Fill-Area Attribute

Functions 145

OpenGL Fill-Pattern Function 145

OpenGL Texture and InterpolationPatterns 146

OpenGL Wire-Frame Methods 147

OpenGL Front-Face Function 150

5-11 Character Attributes 150

5-12 OpenGL Character-Attribute

Functions 153

5-13 OpenGL Antialiasing Functions 153

5-14 OpenGL Query Functions 154

5-15 OpenGL Attribute Groups 155

5-16 Summary 155

Implementation Algorithmsfor Graphics Primitives

and Attributes

Line-Drawing Algorithms 162

Line Equations 162

DDA Algorithm 163

Bresenham's Line Algorithm 164

Displaying Polylines 168

Parallel Line Algorithms 168

6-1

6-2

Contents 9

6-3 Setting Frame-Buffer Values 170

6-4 Circle-Generating Algorithms 171

Properties of Circles 171

Midpoint Circle Algorithm 173

6-5 Ellipse-Generating Algorithms 177

Properties of Ellipses 177

Midpoint Ellipse Algorithm 178

6-6 Other Curves 184

Conic Sections 185

Polynomials and Spline Curves 186

6-7 Parallel Curve Algorithms 187

6-8 Pixel Addressing and ObjectGeometry 187

Screen Grid Coordinates 188

Maintaining Geometric PropertiesofDisplayed Objects 188

6-9 Attribute Implementations for

Straight-Line Segments and Curves 190

Line Width 190

Line Style 192

Pen and Brush Options 193

Curve Attributes 194

6-10 General Scan-Line Polygon-FillAlgorithm 195

6-11 Scan-Line Fill of Convex Polygons 199

6-12 Scan-Line Fill for Regions with Curved

Boundaries 200

6-13 Fill Methods for Areas with IrregularBoundaries 200

Boundary-Fill Algorithm 200

Flood-Fill Algorithm 204

6-14 Implementation Methods for Fill

Styles 204

Fill Styles 205

Color-Blended Fill Regions 205

6-15 Implementation Methods for

Antialiasing 207

Supersampling Straight-Line Segments 208

Subpixel Weighting Masks 210

Area Sampling Straight-Line Segments 210

Filtering Techniques 210

Pixel Phasing 210

Compensatingfor Line-IntensityDifferences 211

Antialiasing Area Boundaries 212

6-16 Summary 214

Two-Dimensional Geometric

Transformations 219

7-1 Basic Two-Dimensional Geometric

Transformations 220

Two-Dimensional Translation 220

Two-Dimensional Rotation 222

Two-Dimensional Scaling 224

7-2 Matrix Representations and

Homogeneous Coordinates 225

Homogeneous Coordinates 226

Two-Dimensional Translation Matrix 227

Two-Dimensional Rotation Matrix 227

Two-Dimensional Scaling Matrix 227

7-3 Inverse Transformations 228

7-4 Two-Dimensional CompositeTransformations 228

Composite Two-Dimensional

Translations 229

Composite Two-Dimensional Rotations 229

Composite Two-Dimensional Scalings 229

General Two-Dimensional Pivot-Point

Rotation 230

General Two-Dimensional Fixed-Point

Scaling 230

General Two-Dimensional ScalingDirections 231

Matrix Concatenation Properties 232

General Two-Dimensional CompositeTransformations and ComputationalEfficiency 233

Two-Dimensional Rigid-BodyTransformation 234

Constructing Two-Dimensional Rotation

Matrices 235

Two-Dimensional Composite-MatrixProgramming Example 235

7-5 Other Two-Dimensional

Transformations 240

Reflection 240

Shear 242

7-6 Raster Methods for Geometric

Transformations 244

7-7 OpenGL Raster Transformations 245

7-8 Transformations between Two-

Dimensional Coordinate Systems 246

10 Contents

7-9 OpenGL Functions for Two-Dimensional

Geometric Transformations 248

Basic OpenGL Geometric

Transformations 248

OpenGL Matrix Operations 250

7-10 OpenGL Geometric-Transformation

Programming Examples 252

7-11 Summary 253

Two-Dimensional Viewing 257

8-1 The Two-Dimensional ViewingPipeline 258

8-2 The Clipping Window 259

Viewing-Coordinate Clipping Window 260

World-Coordinate Clipping Window 260

8-3 Normalization and ViewportTransformations 261

Mapping the Clipping Window into a

Normalized Viewport 261

Mapping the Clipping Window into a

Normalized Square 263

Display of Character Strings 265

Split-Screen Ejfects and MultipleOutput Devices 265

8-4 OpenGL Two-Dimensional ViewingFunctions 265

OpenGL Projection Mode 265

GLU Clipping-Window Function 266

OpenGL Viewport Function 266

Creating a GLUT Display Window 267

Setting the GLUT Display-Window Mode and

Color 268

GLUT Display-Window Identifier 268

Deleting a GLUT Display Window 268

Current GLUT Display Window 268

Relocating and Resizing a GLUT DisplayWindow 269

Managing Multiple GLUT DisplayWindows 269

GLUT Subwindows 269

Selecting a Display-Window Screen-Cursor

Shape 270

Viewing Graphics Objects in a GLUT DisplayWindow 271

Executing the Application Program 271

Other GLUT Functions 272

OpenGL Tivo-Dimensional Viewing ProgramExample 272

8-5 Clipping Algorithms 274

8-6 Two-Dimensional Point Clipping 274

8-7 Two-Dimensional Line Clipping 275

Cohen-Sutherland Line Clipping 276

Liang-Barsky Line Clipping 281

Nicholl-Lee-Nicholl Line Clipping 284

Line Clipping Using Nonrectangular PolygonClip Windows 286

Line Clipping Using Nonlinear Clipping-Window Boundaries 286

8-8 Polygon Fill-Area Clipping 287

Sutherland-Hodgman PolygonClipping 289

Weiler-Atherton Polygon Clipping 293

Polygon Clipping Using Nonrectangular

Polygon Clip Windows 295

Polygon Clipping Using Nonlinear Clipping-Window Boundaries 296

8-9 Curve Clipping 296

8-10 Text Clipping 297

8-11 Summary 298

Three-Dimensional Geometric

Transformations 303

9-1 Three-Dimensional Translation 304

9-2 Three-Dimensional Rotation 305

Three-Dimensional Coordinate-Axis

Rotations 306

General Three-Dimensional Rotations 308

Quaternion Methodsfor Three-Dimensional

Rotations 313

9-3 Three-Dimensional Scaling 317

9-4 Composite Three-Dimensional

Transformations 319

9-5 Other Three-Dimensional

Transformations 322

Three-Dimensional Reflections 322

Three-Dimensional Shears 323

9-6 Transformations between Three-

Dimensional Coordinate Systems 323

9-7 Affine Transformations 324

Contents 11

9-8 OpenGL Geometric-Transformation

Functions 324

OpenGL Matrix Stacks 324

9-9 OpenGL Three-Dimensional

Geometric-Transformation ProgrammingExamples 326

9-10 Summary 327

|W Three-Dimensional Viewing 331

10-1 Overview of Three-Dimensional

Viewing Concepts 332

Viewing a Three-Dimensional Scene 332

Projections 332

Depth Cueing 333

Identifying Visible Lines and Surfaces 333

Surface Rendering 333

Exploded and Cutaway Views 333

Three-Dimensional and StereoscopicViewing 334

10-2 The Three-Dimensional ViewingPipeline 334

10-3 Three-Dimensional Viewing-CoordinateParameters 336

The View-Plane Normal Vector 336

The View-Up Vector 337

The uvn Viewing-Coordinate ReferenceFrame 337

Generating Three-Dimensional ViewingEffects 338

10-4 Transformation from World to ViewingCoordinates 338

10-5 Projection Transformations 340

10-6 Orthogonal Projections 340

Axonometric and Isometric OrthogonalProjections 341

Orthogonal Projection Coordinates 341

Clipping Window and Orthogonal-ProjectionView Volume 342

Normalization Transformation for an

Orthogonal Projection 344

10-7 Oblique Parallel Projections 3445

Oblique Parallel Projections in Draftingand Design 346

Cavalier and Cabinet Oblique Parallel

Projections 347

Oblique Parallel-Projection Vector 348

Clipping Window and ObliqueParallel-Projection View Volume 349

Oblique Parallel-Projection TransformationMatrix 349

Normalization Transformationfor an ObliqueParallel Projection 350

10-8 Perspective Projections 351

Perspective-Projection TransformationCoordinates 351

Perspective-Projection Equations:Special Cases 352

Vanishing Pointsfor PerspectiveProjections 354

Perspective-Projection View Volume 355

Perspective-Projection TransformationMatrix 356

Symmetric Perspective-ProjectionFrustum 357

Oblique Perspective-Projection Frustum 359

Normalized Perspective-ProjectionTransformation Coordinates 362

10-9 The Viewport Transformation and Three-

Dimensional Screen Coordinates 365

10-10 OpenGL Three-Dimensional ViewingFunctions 365

OpenGL Viewing-TransformationFunction 366

OpenGL Orthogonal-ProjectionFunction 366

OpenGL Symmetric Perspective-ProjectionFunction 368

OpenGL General Perspective-ProjectionFunction 368

OpenGL Viewports and DisplayWindows 369

OpenGL Three-Dimensional Viewing ProgramExample 369

10-11 Three-Dimensional ClippingAlgorithms 371

Clipping in Three-Dimensional HomogeneousCoordinates 372

Three-Dimensional Region Codes 373

Three-Dimensional Point and Line

Clipping 374

Three-Dimensional Polygon Clipping 376

Three-Dimensional Curve Clipping 377

Arbitrary Clipping Planes 377

Contents

O-l2 OpenGL Optional Clipping Planes

°-13 Summary 380

379

11-1

11-2

11-3

11-4

11-5

12-1

12-2

12-3

12-4

12-5

12-6

12-7

12-8

12-9

12-10

12-11

Hierarchical Modeling 383

Basic Modeling Concepts 384

System Representations 384

Symbol Hierarchies 385

Modeling Packages 387

General Hierarchical ModelingMethods 387

Local Coordinates 388

Modeling Transformations 388

Creating Hierarchical Structures 388

Hierarchical Modeling Using OpenGLDisplay Lists 390

Summary 391

Computer Animation 393

Raster Methods for ComputerAnimation 394

Double Buffering 394

Generating Animations Using Raster

Operations 395

Design of Animation Sequences 396

Traditional Animation Techniques 397

General Computer-AnimationFunctions 398

Computer-Animation Languages 398

Key-Frame Systems 399

Morphing 399

Simulating Accelerations 401

Motion Specifications 404

Direct Motion Specification 404

Goal-Directed Systems 404

Kinematics and Dynamics 405

Character Animation 406

Articulated Figure Animation 406

Motion Capture 407

Periodic Motions 408

OpenGL Animation Procedures 409

Summary 412

13-1

13-2

13-3

13-4

13-5

13-6

13-7

14-1

14-2

14-3

14-4

14-5

14-6

14-7

14-8

Three-Dimensional

Object Representations 417

Polyhedra 418

OpenGL Polyhedron Functions 418

OpenGL Polygon Fill-Area Functions 418

GLUT Regular Polyhedron Functions 418

Example GLUT Polyhedron Program 420

Curved Surfaces 421

Quadric Surfaces 422

Sphere 422

Ellipsoid 422

Torus 423

Superquadrics 424

Superellipse 424

Superellipsoid 425

OpenGL Quadric-Surface and

Cubic-Surface Functions 425

GLUT Quadric-Surface Functions 425

GLUT Cubic-Surface Teapot Function 426

GLU Quadric-Surface Functions 427

Example Program Using GLUT and GLU

Quadric-Surface Functions 429

Summary 431

Spline Representations 435

Interpolation and ApproximationSplines 436

Parametric Continuity Conditions 437

Geometric Continuity Conditions 438

Spline Specifications 439

Spline Surfaces 440

Trimming Spline Surfaces 440

Cubic-Spline Interpolation Methods 441

Natural Cubic Splines 441

Hermite Interpolation 442

Cardinal Splines 443

Kochanek-Bartels Splines 447

Bezier Spline Curves 447

Bezier Curve Equations 448

Example Bezier Curve-GeneratingProgram 449

Contents 13

Properties of Bezier Curves 452

Design Techniques Using Bezier Curves 453

Cubic Bezier Curves 454

14-9 Bezier Surfaces 455

14-10 B-Spline Curves 457

B-Spline Curve Equations 457

Uniform Periodic B-Spline Curves 458

Cubic Periodic B-Spline Curves 461

Open Uniform B-Spline Curves 463

Nonuniform B-Spline Curves 464

14-11 B-Spline Surfaces 466

14-12 Beta-Splines 466

Beta-Spline Continuity Conditions 466

Cubic Periodic Beta-Spline Matrix

Representation 467

14-13 Rational Splines 467

14-14 Conversion Between SplineRepresentations 469

14-15 Displaying Spline Curves and

Surfaces 470

Horner's Ride 471

Forward-Difference Calculations 471

Subdivision Methods 472

14-16 OpenGL Approximation-SplineFunctions 474

OpenGL Bezier-Spline Curve Functions 474

OpenGL Bezier-Spline SurfaceFunctions 477

GLU B-Spline Curve Functions 479

GLU B-Spline Surface Functions 481

GLU Surface-Trimming Functions 483

14-17 Summary 485

Other Three-Dimensional

object Representations 491

15-1 Blobby Objects 492

15-2 Sweep Representations 493

15-3 Constructive Solid-GeometryMethods 494

15-4 Octrees 496

15-5 BSP Trees 498

15-6 Physically Based Modeling 499

15-7 Summary 500

1 ' Visible-Surface

Detection Methods 503

16-1 Classification of Visible-Surface Detection

Algorithms 504

16-2 Back-Face Detection 504

16-3 Depth-Buffer Method 505

16-4 A-Buffer Method 506

16-5 Scan-Line Method 510

16-6 Depth-Sorting Method 511

16-7 BSP-Tree Method 514

16-8 Area-Subdivision Method 515

16-9 Octree Methods 517

16-10 Ray-Casting Method 518

16-11 Comparison of Visibility-DetectionMethods 519

16-12 Curved Surfaces 520

Curved-Surface Representations 520

Surface Contour Plots 520

16-13 Wire-Frame Visibility Methods 521

Wire-Frame Surface-Visibility

Algorithms 521

Wire-Frame Depth-Cueing Algorithm 522

16-14 OpenGL Visibility-DetectionFunctions 523

OpenGL Polygon-Culling Functions 523

OpenGL Depth-Buffer Functions 523

OpenGL Wire-Frame Surface-VisibilityMethods 525

OpenGL Depth-Cueing Function 525

16-15 Summary 526

Illumination Models and

Surface-Rendering Methods 531

17-1 Light Sources 532

Point Light Sources 533

Infinitely Distant Light Sources 533

Radial Intensity Attenuation 533

Directional Light Sources and Spotlight

Effects 534

Angidar Intensity Attenuation 535

Extended Light Sources and the Warn

Model 536

14 Contents

17-2 Surface Lighting Effects 536

17-3 Basic Illumination Models 537

Ambient Light 537

Diffuse Reflection 538

Specular Reflection and the PhongModel 540

Combined Diffuse and Specular

Reflections 543

Diffuse and Specular Reflections from Multiple

Light Sources 543

Surface Light Emissions 543

Basic Illumination Model with IntensityAttenuation and Spotlights 544

RGB Color Considerations 545

Other Color Representations 546

Luminance 546

17-4 Transparent Surfaces 546

Translucent Materials 547

Light Refraction 547

Basic Transparency Model 548

17-5 Atmospheric Effects 549

17-6 Shadows 550

17-7 Camera Parameters 550

17-8 Displaying Light Intensities 550

Distributing System Intensity Levels 551

Gamma Correction and Video LookupTables 552

Displaying Continuous-Tone Images 553

17-9 Halftone Patterns and DitheringTechniques 553

Halftone Approximations 555

Dithering Techniques 557

17-10 Polygon Rendering Methods 559

Constant-Intensity Surface Rendering 560

Gouraud Surface Rendering 560

Phong Surface Rendering 562

Fast Phong Surface Rendering 563

17-11 OpenGL Illumination and

Surface-Rendering Functions 564

OpenGL Point Light-Source Function 564

Specifying an OpenGL Light-Source Position

and Type 565

Specifying OpenGL Light-Source Colors 566

Specifying Radial-Intensity Attenuation

Coefficientsfor an OpenGL Light Source 567

OpenGL Directional Light Sources

(Spotlights) 567

OpenGL Global Lighting Parameters 568

OpenGL Surface-Property Function 569

OpenGL Illumination Model 570

OpenGL Atmospheric Effects 571

OpenGL Transparency Functions 572

OpenGL Surface-RenderingFunctions 573

OpenGL Halftoning Operations 574

17-12 Summary 575

' '<' ! Texturing and Surface-Detail

Methods 579

18-1 Modeling Surface Detail with

Polygons 580

18-2 Texture Mapping 580

Linear Texture Patterns 581

Surface Texture Patterns 581

Volume Texture Patterns 584

Texture Reduction Patterns 585

Procedural Texturing Methods 585

18-3 Bump Mapping 585

18-4 Frame Mapping 586

18-5 OpenGL Texture Functions 587

OpenGL Line-Texture Functions 587

OpenGL Surface-Texture Functions 590

OpenGL Volume-Texture Functions 592

OpenGL Color Options for Texture

Patterns 592

OpenGL Texture-Mapping Options 593

OpenGL Texture Wrapping 593

Copying OpenGL Texture Patterns from the

Frame Buffer 594

OpenGL Texture-Coordinate Arrays 594

Naming OpenGL Texture Patterns 594

OpenGL Texture Subpatterns 596

OpenGL Texture Reduction Patterns 596

OpenGL Texture Borders 597

OpenGL Proxy Textures 597

Automatic Texturing ofQuadricSurfaces 598

Homogeneous Texture Coordinates 598

Additional OpenGL Texture

Options 599

18-6 Summary 599

Contents 15

19-1

19-2

19-3

19-4

19-5

19-6

19-7

19-8

19-9

19-10

20-1

20-2

Color Models and Color

Applications 603

Properties of Light 604

The Electromagnetic Spectrum 604

Psychological Characteristics ofColor 605

Color Models 606

Primary Colors 606

Intuitive Color Concepts 607

Standard Primaries and the ChromaticityDiagram 607

The XYZ Color Model 608

Normalized XYZ Values 608

The CIE Chromaticity Diagram 609

Color Gamuts 609

Complementary Colors 609

Dominant Wavelength 610

Purity 610

The RGB Color Model 610

The YIQ and Related Color Models 612

The YIQ Parameters 612

Transformations Between RGB and YIQ Color

Spaces 612

The YUV and YCrCb Systems 613

The CMY and CMYK Color

Models 613

The CMY Parameters 613

Transformations Between CMY and RGB

Color Spaces 614

The HSV Color Model 614

The HS V Parameters 614

Selecting Shades, Tints, and Tones 615

Transformations Between HSV and RGB Color

Spaces 616

The HLS Color Model 618

Color Selection and Applications 619

Summary 619

Interactive Input Methods and

Graphical User Interfaces

Graphical Input Data 624

Logical Classification of Input

623

Devices 624

Locator Devices 624

Stroke Devices 625

String Devices 625

Valuator Devices 625

Choice Devices 625

Pick Devices 626

20-3 Input Functions for GraphicalData 627

Input Modes 628

Echo Feedback 628

Callback Functions 628

20-4 Interactive Picture-Construction

Techniques 629

Basic Positioning Methods 629

Dragging 629

Constraints 629

Grids 630

Rubber-Band Methods 630

Gravity Field 631

Interactive Painting and DrawingMethods 631

20-5 Virtual-Reality Environments 632

20-6 OpenGL Interactive Input-DeviceFunctions 632

GLUT Mouse Functions 633

GLUT Keyboard Functions 637

GLUT Tablet Functions 641

GLUT Spaceball Functions 642

GLUT Button-Box Function 642

GLUT Dials Function 642

OpenGL Picking Operations 643

20-7 OpenGL Menu Functions 648

Creating a GLUT Menu 648

Creating and Managing Multiple GLUTMenus 650

Creating GLUT Submenus 651

Modifying GLUT Menus 653

20-8 Designing a Graphical User

Interface 654

The User Dialogue 654

Windows and Icons 654

Accommodating Multiple Skill Levels 655

Consistency 655

Minimizing Memorization 655

Backup and Error Handling 656

Feedback 656

20-9 Summary 657

16 Contents

Global Illumination 663

21-1 Ray-Tracing Methods 664

Basic Ray-Tracing Algorithm 664

Ray-Surface Intersection

Calculations 667

Ray-Sphere Intersections 668

Ray-Polyhedron Intersections 669

Reducing Object-Intersection

Calculations 670

Space-Subdivision Methods 670

Simulating Camera Focusing

Effects 672

Antialiased Ray Tracing 674

Distributed Ray Tracing 675

21-2 Radiosity Lighting Model 678

Radiant-Energy Terms 678

The Basic Radiosity Model 679

Progressive Refinement RadiosityMethod 682

21-3 Environment Mapping 684

21-4 Photon Mapping 685

21-5 Summary 686

Programmable Shaders 689

22-1 A History of ShadingLanguages 690

Cook's Shade Trees 690

Perlin's Pixel Stream Editor 692

RenderMart 692

22-2 The OpenGL Pipeline 694

The Fixed-Function Pipeline 694

Changing the Pipeline Structure 695

Vertex Shaders 696

Fragment Shaders 696

Geometry Shaders 696

Tessellation Shaders 696

22-3 The OpenGL ShadingLanguage 697

Shader Structure 697

Using Shaders in OpenGL 699

Basic Data Types 703

Vectors 703

Matrices 704

Structures and Arrays 704

Control Structures 705

GLSL Functions 705

Communicating with OpenGL 706

22-4 Shader Effects 707

A Phong Shader 708

Texture Mapping 711

Bump Mapping 713

22-5 Summary 717

Algorithmic Modeling 719

23-1 Fractal-Geometry Methods 720

Fractal Generation Procedures 721

Classification ofFractals 721

Fractal Dimension 722

Geometric Construction of Deterministic

Self-Similar Fractals 724

Geometric Construction ofStatisticallySelf-Similar Fractals 727

Affine Fractal-Construction Methods 728

Random Midpoint-DisplacementMethods 728

Controlling Terrain Topography 730

Self-Squaring Fractals 732

Self-Inverse Fractals 741

23-2 Particle Systems 743

23-3 Grammar-Based ModelingMethods 744

23-4 Summary 746

Visualization of Data Sets 749

24-1 Visual Representations for Scalar

Fields 750

24-2 Visual Representations for Vector

Fields 752

24-3 Visual Representations for Tensor

Fields 752

24-4 Visual Representations for Multivariate

Data Fields 753

24-5 Summary 753

Contents 17

Mathematics for ComputerGraphics 755

A-1 Coordinate Reference Frames 755

Two-Dimensional Cartesian Screen

Coordinates 755

Standard Two-Dimensional Cartesian

Reference Frames 756

Polar Coordinates in the xy Plane 756

Standard Three-Dimensional Cartesian

Reference Frames 757

Three-Dimensional Cartesian Screen

Coordinates 757

Three-Dimensional Curvilinear-Coordinate

Systems 758

Solid Angle 759

A-2 Points and Vectors 759

Point Properties 759

Vector Properties 760

Vector Addition and Scalar

Multiplication 761

Scalar Product of Two Vectors 762

Vector Product of Two Vectors 762

A-3 Tensors 763

A-4 Basis Vectors and the Metric Tensor 763

Determining Basis Vectorsfor a Coordinate

Space 764

Orthonormal Basis 764

Metric Tensor 765

A-5 Matrices 766

Scalar Multiplication and Matrix

Addition 766

Matrix Multiplication 767

Matrix Transpose 768

Determinant of a Matrix 768

Matrix Inverse 768

A-6 Complex Numbers 769

Basic Complex Arithmetic 769

Imaginary Unit 770

Complex Conjugate and Modidus ofa ComplexNumber 770

Complex Division 770

Polar-Coordinate Representation for aComplex Number 771

A-7 Quaternions 771

A-8 Nonparametric Representations 772

A-9 Parametric Representations 773

A-10 Rate-of-Change Operators 774

Gradient Operator 774

Directional Derivative 775

General Form ofthe Gradient Operator 775

Laplace Operator 775

Divergence Operator 776

Curl Operator 776

A-11 Rate-of-Change Integral TransformationTheorems 776

Stokes's Theorem 777

Green's Theoremfor a Plane Surface 777

Divergence Theorem 778

Green's Transformation Equations 779

A-12 Area and Centroid of a Polygon 779

Area of a Polygon 779

Centroid ofa Polygon 780

A-13 Calculating Properties of Polyhedra 781

A-14 Numerical Methods 782

Solving Sets ofLinear Equations 782

Finding Roots of Nonlinear Equations 784

Evaluating Integrals 785

Solving Ordinary Differential Equations 787

Solving Partial Differential Equations 788

Least-Squares Curve-Fitting MethodsforData Sets 789

Graphics File Formats 793

Image-File Configurations 791

Color-Reduction Methods 792

Uniform Color Reduction 792

Popularity Color Reduction 792

Median-Cut Color Reduction 793

B-3 File-Compression Techniques 793

Run-Length Encoding 794

LZW Encoding 794

Other Pattern-Recognition CompressionMethods 795

Huffman Encoding 795

Arithmetic Encoding 797

Discrete Cosine Transform 798

B-4 Composition of the Major File

Formats 800

JPEG: Joint Photographic Experts Group 800

18 Contents

CGM: Computer-Graphics MetafileFormat 802

TIFF: Tag Image-File Format 802

PNG: Portable Network-GraphicsFormat 803

XBM: X Window System Bitmap Format

and XPM: X Window System PixmapFormat 803

Adobe Photoshop Format 803

MacPaint: Macintosh Paint Format 804

PICT: Picture Data Format 804

BMP: Bitmap Format 804

PCX: PC Paintbrush File Format 804

TGA: Truevision Graphics-AdapterFormat 804

GIF: Graphics Interchange Format 805

B-5 Summary 805

The World of OpenGL 807

C-1 The Evolution of OpenGL 807

The Early Years: OpenGL 1.x 808

OpenGL Goes Tiny: OpenGL ES 1.x 809

Under New Management: OpenGL and

Khronos Group 810

Programmable Everything: OpenGL 2.x 810

Tiny Programs: OpenGL ES 2.x 811

Geometry and Vertex Processing Evolution:

OpenGL 3.x 811

This Generation: OpenGL 4.x 813

The OpenGL Extension Mechanism 814

Where Next? 815

C-2 OpenGL beyond C and C++ 816

OpenGLfor Java 816

Multithreading 819

Python and OpenGL 822

Conclusions and Directions 827

C-3 GPU Architecture, Past, Present,and Future 827

The Early Days 828

The Middle Ages 829

Modern GPUs 830

Parallelism 830

Getting the Most out ofa Modern GPU 834

Balance the Workload 834

Always Move Forwards 835

Feed the Pipeline 835

Make Best Use of Your Resources 835

Bibliography 837

Index 849

OpenGL Function Index 883

Core Library Functions 883

GLSL Library Functions 884

GLU Library Functions 885

GLUT Library Functions 885