?????? 1 CHAPTER 1 Graphics Systems and Models 3 1.1 Applications of Computer Graphics 4 1.1.1 Display of Information............. 4 1.1.2 Design.................... 5 1.1.3 Simulation and Animation........... 5 1.1.4 User Interfaces................ 6 1.2 A Graphics System 7 1.2.1 Pixels and the Frame Buffer........... 8 1.2.2 Output Devices................ 9 1.2.3 Input Devices................ 11 1.3 Images: Physical and Synthetic 11 1.3.1 Objects and Viewers............. 12 1.3.2 Light and Images.............. 13 1.3.3 Ray Tracing................ 15 1.4 The Pinhole Camera 18 1.5 The Human Visual System 20 1.6 The Synthetic-Camera Model 21 1.7 The Programmer s Interface 24 1.7.1 The Pen-Plotter Model............ 24 1.7.2 Three-Dimensional APIs........... 27 1.7.3 A Sequence of Images............ 29 1.7.4 The Modeling Rendering Paradigm...... 30 1.8 Graphics Architectures 31 1.8.1 Display Processors.............. 32 1.8.2 Pipeline Architectures............ 33 1.8.3 The Graphics Pipeline............ 33 1.8.4 Vertex Processing.............. 34 1.8.5 Clipping and Primitive Assembly....... 35 1.8.6 Rasterization................ 35 1.8.7 Fragment Processing............. 36 1.9 Performance Characteristics 36
2?????? 1.10 Programmable Pipelines 37 1.11 Summary and Notes 38 1.12 Suggested Readings 39 Exercises 39 CHAPTER 2 Graphics Programming 43 2.1 The Sierpinski Gasket 43 2.2 Programming Two-Dimensional Applications 45 2.2.1 Coordinate Systems............. 49 2.3 The OpenGL API 51 2.3.1 Graphics Functions............. 51 2.3.2 The Graphics Pipeline and State Machines... 53 2.3.3 The OpenGL Interface............ 53 2.4 Primitives and Attributes 54 2.4.1 Polygon Basics............... 57 2.4.2 Polygon Types in OpenGL.......... 58 2.4.3 Approximating a Sphere........... 59 2.4.4 Text.................... 61 2.4.5 Curved Objects............... 62 2.4.6 Attributes................. 63 2.5 Color 64 2.5.1 RGB Color................. 68 2.5.2 Indexed Color................ 70 2.5.3 Setting of Color Attributes.......... 72 2.6 Viewing 72 2.6.1 The Orthographic View........... 73 2.6.2 Two-Dimensional Viewing.......... 74 2.6.3 Matrix Modes................ 75 2.7 Control Functions 76 2.7.1 Interaction with the Window System...... 76 2.7.2 Aspect Ratio and Viewports......... 78
?????? 3 2.7.3 The main, display, and myinit Functions.... 79 2.7.4 Program Structure.............. 81 2.8 The Gasket Program 81 2.9 Polygons and Recursion 83 2.10 Plotting Implicit Functions 85 2.10.1 Marching Squares.............. 86 2.11 The Three-Dimensional Gasket 93 2.11.1 Use of Three-Dimensional Points....... 93 2.11.2 Use of Polygons in Three Dimensions...... 95 2.11.3 Hidden-Surface Removal........... 96 2.12 Summary and Notes 97 2.13 Suggested Readings 99 Exercises 100 CHAPTER 3 Input and Interaction 105 3.1 Interaction 105 3.2 Input Devices 106 3.2.1 Physical Input Devices............ 107 3.2.2 Logical Devices............... 110 3.2.3 Input Modes................ 111 3.3 Clients and Servers 113 3.4 Display Lists 114 3.4.1 Definition and Execution of Display Lists.... 116 3.4.2 Text and Display Lists............ 118 3.4.3 Fonts in GLUT............... 121 3.5 Programming Event-Driven Input 122 3.5.1 Using the Pointing Device.......... 122 3.5.2 Window Events............... 126 3.5.3 Keyboard Events.............. 127 3.5.4 The Display and Idle Callbacks........ 128
4?????? 3.5.5 Window Management............ 129 3.6 Menus 129 3.7 Picking 131 3.7.1 Picking and Selection Mode.......... 132 3.8 A Simple Paint Program 138 3.9 Building Interactive Models 144 3.10 Animating Interactive Programs 147 3.10.1 The Rotating Square............. 147 3.10.2 Double Buffering.............. 149 3.10.3 Other Buffering Problems........... 150 3.11 Design of Interactive Programs 152 3.11.1 Toolkits, Widgets, and the Frame Buffer.... 153 3.12 Logic Operations 154 3.12.1 Drawing Erasable Lines........... 155 3.12.2 XOR and Color............... 157 3.12.3 Cursors and Overlay Planes.......... 158 3.13 Summary and Notes 159 3.14 Suggested Readings 160 Exercises 160 CHAPTER 4 Geometric Objects and Transformations 165 4.1 Scalars, Points, and Vectors 166 4.1.1 Geometric Objects.............. 166 4.1.2 Coordinate-Free Geometry.......... 168 4.1.3 The Mathematical View: Vector and Affine Spaces 168 4.1.4 The Computer-Science View......... 169 4.1.5 Geometric ADTs.............. 170 4.1.6 Lines.................... 171 4.1.7 Affine Sums................. 171
?????? 5 4.1.8 Convexity................. 172 4.1.9 Dot and Cross Products........... 173 4.1.10 Planes................... 174 4.2 Three-Dimensional Primitives 175 4.3 Coordinate Systems and Frames 176 4.3.1 Representations and N-tuples......... 178 4.3.2 Changes of Coordinate Systems........ 179 4.3.3 Example of Change of Representation..... 181 4.3.4 Homogeneous Coordinates.......... 183 4.3.5 Example of Change in Frames......... 186 4.3.6 Working with Representations......... 187 4.4 Frames in OpenGL 189 4.5 Modeling a Colored Cube 193 4.5.1 Modeling of a Cube............. 194 4.5.2 Inward- and Outward-Pointing Faces...... 195 4.5.3 Data Structures for Object Representation... 196 4.5.4 The Color Cube............... 197 4.5.5 Bilinear Interpolation............ 198 4.5.6 Vertex Arrays................ 200 4.6 Affine Transformations 202 4.7 Translation, Rotation, and Scaling 204 4.7.1 Translation................. 205 4.7.2 Rotation.................. 205 4.7.3 Scaling................... 207 4.8 Transformations in Homogeneous Coordinates 207 4.8.1 Translation................. 208 4.8.2 Scaling................... 209 4.8.3 Rotation.................. 210 4.8.4 Shear................... 211 4.9 Concatenation of Transformations 212 4.9.1 Rotation About a Fixed Point......... 213 4.9.2 General Rotation.............. 214 4.9.3 The Instance Transformation......... 215
6?????? 4.9.4 Rotation About an Arbitrary Axis....... 217 4.10 OpenGL Transformation Matrices 220 4.10.1 The Current Transformation Matrix...... 220 4.10.2 Rotation, Translation, and Scaling....... 221 4.10.3 Rotation About a Fixed Point in OpenGL... 222 4.10.4 Order of Transformations........... 222 4.10.5 Spinning of the Cube............. 223 4.10.6 Loading, Pushing, and Popping Matrices.... 225 4.11 Interfaces to Three-Dimensional Applications 226 4.11.1 Using Areas of the Screen........... 226 4.11.2 A Virtual Trackball............. 227 4.11.3 Smooth Rotations.............. 229 4.11.4 Incremental Rotation............. 231 4.12 Quaternions 232 4.12.1 Complex Numbers and Quaternions...... 232 4.12.2 Quaternions and Rotation.......... 233 4.13 Summary and Notes 235 4.14 Suggested Readings 236 Exercises 237 CHAPTER 5 Viewing 241 5.1 Classical and Computer Viewing 241 5.1.1 Classical Viewing.............. 243 5.1.2 Orthographic Projections........... 244 5.1.3 Axonometric Projections........... 245 5.1.4 Oblique Projections............. 246 5.1.5 Perspective Viewing............. 247 5.2 Viewing with a Computer 249 5.3 Positioning of the Camera 250 5.3.1 Positioning of the Camera Frame....... 250 5.3.2 Two Viewing APIs.............. 255 5.3.3 The Look-At Function............ 258
?????? 7 5.3.4 Other Viewing APIs............. 259 5.4 Simple Projections 260 5.4.1 Perspective Projections............ 261 5.4.2 Orthogonal Projections............ 264 5.5 Projections in OpenGL 264 5.5.1 Perspective in OpenGL............ 265 5.5.2 Parallel Viewing in OpenGL......... 267 5.6 Hidden-Surface Removal 268 5.6.1 Culling................... 270 5.7 Interactive Mesh Displays 271 5.7.1 Meshes................... 271 5.7.2 Walking Through a Scene........... 273 5.7.3 Polygon Offset............... 275 5.8 Parallel-Projection Matrices 276 5.8.1 Projection Normalization........... 276 5.8.2 Orthogonal-Projection Matrices........ 277 5.8.3 Oblique Projections............. 280 5.9 Perspective-Projection Matrices 283 5.9.1 Perspective Normalization.......... 283 5.9.2 OpenGL Perspective Transformations..... 287 5.10 Projections and Shadows 288 5.11 Summary and Notes 291 5.12 Suggested Readings 292 Exercises 292 CHAPTER 6 Shading 295 6.1 Light and Matter 296 6.2 Light Sources 299 6.2.1 Color Sources................ 300 6.2.2 Ambient Light............... 301
8?????? 6.2.3 Point Sources................ 301 6.2.4 Spotlights................. 302 6.2.5 Distant Light Sources............ 303 6.3 The Phong Reflection Model 303 6.3.1 Ambient Reflection............. 305 6.3.2 Diffuse Reflection.............. 305 6.3.3 Specular Reflection............. 307 6.4 Computation of Vectors 309 6.4.1 Normal Vectors............... 309 6.4.2 Angle of Reflection.............. 312 6.4.3 Use of the Halfway Vector.......... 313 6.5 Polygonal Shading 313 6.5.1 Flat Shading................ 314 6.5.2 Interpolative and Gouraud Shading...... 316 6.5.3 Phong Shading............... 317 6.6 Approximation of a Sphere by Recursive Subdivision 318 6.7 Light Sources in OpenGL 322 6.8 Specification of Materials in OpenGL 324 6.9 Shading of the Sphere Model 326 6.10 Global Rendering 327 6.11 Summary and Notes 329 6.12 Suggested Readings 330 Exercises 330 CHAPTER 7 From Vertices to Fragments 333 7.1 Basic Implementation Strategies 334 7.2 Four Major Tasks 336 7.2.1 Modeling.................. 336
?????? 9 7.2.2 Geometric Processing............ 337 7.2.3 Rasterization................ 338 7.2.4 Fragment Processing............. 339 7.3 Clipping 339 7.4 Line-Segment Clipping 340 7.4.1 Cohen Sutherland Clipping.......... 341 7.4.2 Liang Barsky Clipping............ 343 7.5 Polygon Clipping 345 7.6 Clipping of Other Primitives 348 7.6.1 Bounding Boxes and Volumes......... 348 7.6.2 Curves, Surfaces, and Text.......... 349 7.6.3 Clipping in the Frame Buffer......... 350 7.7 Clipping in Three Dimensions 350 7.8 Rasterization 353 7.9 Bresenham s Algorithm 356 7.10 Testing Algorithms 358 7.11 Scan Conversion of Polygons 359 7.11.1 Inside Outside Testing............ 359 7.11.2 OpenGL and Concave Polygons........ 361 7.11.3 Fill and Sort................ 362 7.11.4 Flood Fill.................. 362 7.11.5 Singularities................ 363 7.12 Hidden-Surface Removal 363 7.12.1 Object-Space and Image-Space Approaches... 364 7.12.2 Sorting and Hidden-Surface Removal...... 365 7.12.3 Scan-Line Algorithms............ 366 7.12.4 Back-Face Removal............. 367 7.12.5 The z-buffer Algorithm............ 367 7.12.6 Scan Conversion with the z Buffer....... 370 7.12.7 Depth Sort and the Painter s Algorithm.... 371 7.12.8 The Scan-Line Algorithm........... 374 7.12.9 Scan-Line Algorithms............ 375
10?????? 7.13 Antialiasing 376 7.14 Display Considerations 378 7.15 Summary and Notes 378 7.16 References 380 Exercises 380 CHAPTER 8 Discrete Techniques 385 8.1 Buffers 385 8.2 Digital Images 387 8.3 Writing into Buffers 390 8.3.1 Writing Modes............... 391 8.3.2 Writing with XOR.............. 393 8.4 Bit and Pixel Operations in OpenGL 394 8.4.1 OpenGL Buffers and the Pixel Pipeline..... 395 8.4.2 Bitmaps.................. 396 8.4.3 Raster Fonts................ 397 8.4.4 Pixels and Images.............. 398 8.4.5 Lookup Tables............... 400 8.5 The Mandelbrot Set 401 8.5.1 Buffers for Picking.............. 404 8.6 Mapping Methods 404 8.7 Texture Mapping 406 8.7.1 Two-Dimensional Texture Mapping...... 407 8.7.2 Texture Mapping in OpenGL......... 413 8.7.3 Texture Objects............... 421 8.7.4 Multitexturing............... 421 8.8 Texture Generation 421 8.9 Environmental Maps 423 8.10 Compositing Techniques 427
?????? 11 8.10.1 Opacity and Blending............ 428 8.10.2 Image Compositing............. 429 8.10.3 Blending and Compositing in OpenGL..... 430 8.10.4 Antialiasing................. 431 8.10.5 Back-to-Front and Front-to-Back Rendering... 433 8.10.6 Depth Cueing and Fog............ 434 8.11 Multirendering and the Accumulation Buffer 435 8.11.1 Scene Antialiasing.............. 436 8.11.2 Bump Mapping and Embossing........ 436 8.11.3 Image Processing.............. 437 8.11.4 Imaging Extensions............. 438 8.11.5 Other Multipass Methods........... 439 8.12 Sampling and Aliasing 440 8.12.1 Sampling Theory.............. 440 8.12.2 Reconstruction............... 444 8.12.3 Quantization................ 447 8.13 Summary and Notes 447 8.14 Suggested Readings 448 Exercises 449 CHAPTER 9 Vertex Shaders 453 9.1 Programmable Shaders 453 9.2 Shading Languages 454 9.2.1 GLSL and Cg................ 454 9.2.2 OpenGL Extensions............. 454 9.3 The OpenGL Shading Language 454 9.4 Examples 454 9.4.1 Moving Vertices............... 454 9.4.2 Phong Shading............... 454 9.4.3 Cartoon Shading.............. 454 9.5 Summary 454
12?????? 9.6 Exercises 454 CHAPTER 10 Fragment Shaders 455 10.1 Fragment Shaders in GLSL 455 10.2 Vertex vs Fragment Phong Shading 455 10.3 Cube Maps 455 10.3.1 Normal Maps................ 455 10.4 Bump Mapping 455 10.5 Summary 455 10.6 Exercises 455 CHAPTER 11 11.1 Symbols and Instances 458 11.2 Hierarchical Models 459 11.3 A Robot Arm 462 Hierarchical and Object-Oriented Modeling 457 11.4 Trees and Traversal 464 11.4.1 A Stack-Based Traversal........... 465 11.5 Use of Tree Data Structures 468 11.6 Animation 472 11.7 Graphical Objects 474 11.7.1 Methods, Attributes, and Messages...... 475 11.7.2 A Cube Object............... 476 11.7.3 Implementing the Cube Object........ 479 11.7.4 Objects and Hierarchy............ 480 11.7.5 Geometric Objects.............. 480 11.8 Scene Graphs 481 11.9 A Simple Scene Graph API 484
?????? 13 11.9.1 The Node Class............... 484 11.9.2 Geometry Nodes............... 486 11.9.3 Camera Class................ 489 11.9.4 Lights and Materials............. 489 11.9.5 Transformations............... 491 11.9.6 The Robot Figure.............. 492 11.9.7 Implementing the Viewer........... 494 11.9.8 Implementing a Node............ 497 11.10 Other Tree Structures 501 11.10.1 CSG Trees................. 501 11.10.2 Shade Trees................. 502 11.10.3 BSP Trees................. 503 11.10.4 Quadtrees and Octrees............ 506 11.11 Graphics and the Web 507 11.11.1 Networks and Protocols........... 508 11.11.2 Hypermedia and HTML........... 509 11.11.3 Databases and VRML............ 510 11.11.4 Java and Applets.............. 511 11.12 Summary and Notes 511 11.13 Suggested Readings 512 Exercises 513 CHAPTER 12 Curves and Surfaces 515 12.1 Representation of Curves and Surfaces 515 12.1.1 Explicit Representation............ 515 12.1.2 Implicit Representations........... 517 12.1.3 Parametric Form.............. 518 12.1.4 Parametric Polynomial Curves........ 519 12.1.5 Parametric Polynomial Surfaces........ 520 12.2 Design Criteria 521 12.3 Parametric Cubic Polynomial Curves 522 12.4 Interpolation 523
14?????? 12.4.1 Blending Functions............. 525 12.4.2 The Cubic Interpolating Patch........ 527 12.5 Hermite Curves and Surfaces 529 12.5.1 The Hermite Form.............. 529 12.5.2 Geometric and Parametric Continuity..... 532 12.6 Bezier Curves and Surfaces 533 12.6.1 Bezier Curves................ 533 12.6.2 Bezier Surface Patches............ 536 12.7 Cubic B-Splines 537 12.7.1 The Cubic B-Spline Curve.......... 537 12.7.2 B-Splines and Basis............. 540 12.7.3 Spline Surfaces............... 541 12.8 General B-Splines 542 12.8.1 Recursively Defined B-Splines......... 543 12.8.2 Uniform Splines............... 544 12.8.3 Nonuniform B-Splines............ 544 12.8.4 NURBS.................. 545 12.9 Rendering of Curves and Surfaces 546 12.9.1 Polynomial Evaluation Methods........ 547 12.9.2 Recursive Subdivision of Bezier Polynomials.. 548 12.9.3 Rendering of Other Polynomial Curves by Subdivision............... 552 12.9.4 Subdivision of Bezier Surfaces......... 552 12.10 The Utah Teapot 554 12.11 Algebraic Surfaces 557 12.11.1 Quadrics.................. 557 12.11.2 Rendering of Surfaces by Ray Casting..... 558 12.11.3 Subdivision Curves and Surfaces........ 559 12.12 Curves and Surfaces in OpenGL 560 12.12.1 Bezier Curves................ 560 12.12.2 Bezier Surfaces............... 562 12.12.3 Displaying the Teapot............ 564
?????? 1 12.12.4 NURBS Functions.............. 566 12.12.5 Quadrics.................. 566 12.13 Summary and Notes 567 12.14 References and Notes 568 Exercises 568 CHAPTER 13 Advanced Rendering 571 13.1 Going Beyond Pipeline Rendering 571 13.2 Ray Tracing 572 13.3 Building a Simple Ray Tracer 576 13.3.1 Recursive Ray Tracing............ 576 13.3.2 Calculating Intersections........... 578 13.3.3 Ray-Tracing Variations............ 581 13.4 The Rendering Equation 582 13.5 Radiosity 583 13.5.1 The Radiosity Equation........... 584 13.5.2 Solving the Radiosity Equation........ 585 13.5.3 Computing Form Factors........... 587 13.5.4 Carrying Out Radiosity........... 589 13.6 RenderMan 591 13.7 Large-Scale Rendering 592 13.7.1 Sort-Middle Rendering............ 593 13.7.2 Sort-Last Rendering............. 595 13.7.3 Sort-First Rendering............. 598 13.8 Image-Based Rendering 599 13.8.1 A Simple Example.............. 600 13.9 Summary and Notes 602 13.10 Suggested Readings 603 Exercises 604