OpenGL Programming Guide: The Official Guide to Learning OpenGL, Versions 3.0 and 3.1 (7th Edition)

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

OpenGL is a powerful software interface used to produce high-quality, computer-generated images and interactive applications using 2D and 3D objects, bitmaps, and color images.   The OpenGL®Programming Guide, Seventh Edition, provides definitive and comprehensive information on OpenGL and the OpenGL Utility Library. The previous edition covered OpenGL through Version 2.1. This seventh edition of the best-selling “red book” describes the latest features of OpenGL Versions 3.0 and 3.1. You will find clear explanations of OpenGL functionality and many basic computer graphics techniques, such as building and rendering 3D models; interactively viewing objects from different perspective points; and using shading, lighting, and texturing effects for greater realism. In addition, this book provides in-depth coverage of advanced techniques, including texture mapping, antialiasing, fog and atmospheric effects, NURBS, image processing, and more. The text also explores other key topics such as enhancing performance, OpenGL extensions, and cross-platform techniques.   This seventh edition has been updated to include the newest features of OpenGL Versions 3.0 and 3.1, including   Using framebuffer objects for off-screen rendering and texture updates Examples of the various new buffer object types, including uniform-buffer objects, transform feedback buffers, and vertex array objects Using texture arrays to increase performance when using numerous textures Efficient rendering using primitive restart and conditional rendering Discussion of OpenGL’s deprecation mechanism and how to verify your programs for future versions of OpenGL   This edition continues the discussion of the OpenGL Shading Language (GLSL) and explains the mechanics of using this language to create complex graphics effects and boost the computational power of OpenGL. The OpenGL Technical Library provides tutorial and reference books for OpenGL. The Library enables programmers to gain a practical understanding of OpenGL and shows them how to unlock its full potential. Originally developed by SGI, the Library continues to evolve under the auspices of the Khronos OpenGL ARB Working Group, an industry consortium responsible for guiding the evolution of OpenGL and related technologies.  

Author(s): Dave Shreiner, The Khronos OpenGL ARB Working Group
Edition: 7
Year: 2009

Language: English
Pages: 1019

Cover Page......Page 1
Title Page......Page 4
ISBN 978-0321552624......Page 5
Contents......Page 8
Figures......Page 22
Tables......Page 26
Examples......Page 30
What This Guide Contains......Page 36
What's New in This Edition......Page 39
What You Should Know Before Reading This Guide......Page 41
How to Obtain the Sample Code......Page 42
Style Conventions......Page 43
Distinguishing Deprecated Features......Page 44
Acknowledgments......Page 46
1. Introduction to OpenGL......Page 52
What Is OpenGL?......Page 53
A Smidgen of OpenGL Code......Page 56
OpenGL Command Syntax......Page 58
OpenGL as a State Machine......Page 60
OpenGL Rendering Pipeline......Page 61
Evaluators......Page 62
Primitive Assembly......Page 63
Texture Assembly......Page 64
OpenGL-Related Libraries......Page 65
Include Files......Page 66
GLUT, the OpenGL Utility Toolkit......Page 68
Animation......Page 73
The Refresh That Pauses......Page 74
Motion = Redraw + Swap......Page 75
OpenGL Contexts......Page 78
Accessing OpenGL Functions......Page 80
2. State Management and Drawing Geometric Objects......Page 82
Clearing the Window......Page 85
Specifying a Color......Page 88
Forcing Completion of Drawing......Page 89
Coordinate System Survival Kit......Page 91
What Are Points, Lines, and Polygons?......Page 93
Specifying Vertices......Page 97
OpenGL Geometric Drawing Primitives......Page 98
Basic State Management......Page 104
Point Details......Page 106
Line Details......Page 107
Polygon Details......Page 111
Normal Vectors......Page 119
Vertex Arrays......Page 121
Step 1: Enabling Arrays......Page 123
Step 2: Specifying Data for the Arrays......Page 124
Step 3: Dereferencing and Rendering......Page 128
Restarting Primitives......Page 134
Instanced Drawing......Page 137
Interleaved Arrays......Page 139
Buffer Objects......Page 142
Creating Buffer Objects......Page 143
Allocating and Initializing Buffer Objects with Data......Page 144
Updating Data Values in Buffer Objects......Page 147
Copying Data Between Buffer Objects......Page 152
Using Buffer Objects with Vertex-Array Data......Page 153
Vertex-Array Objects......Page 155
Attribute Groups......Page 161
Some Hints for Building Polygonal Models of Surfaces......Page 164
An Example: Building an Icosahedron......Page 166
3. Viewing......Page 174
Overview: The Camera Analogy......Page 177
A Simple Example: Drawing a Cube......Page 180
General-Purpose Transformation Commands......Page 185
Thinking about Transformations......Page 188
Modeling Transformations......Page 191
Viewing Transformations......Page 197
Projection Transformations......Page 203
Perspective Projection......Page 204
Orthographic Projection......Page 207
Viewport Transformation......Page 209
Defining the Viewport......Page 210
The Transformed Depth Coordinate......Page 212
Troubleshooting Transformations......Page 213
Manipulating the Matrix Stacks......Page 215
The Modelview Matrix Stack......Page 218
Additional Clipping Planes......Page 219
Building a Solar System......Page 223
Building an Articulated Robot Arm......Page 226
Reversing or Mimicking Transformations......Page 230
4. Color......Page 236
Color Perception......Page 237
Computer Color......Page 239
RGBA versus Color-Index Mode......Page 241
RGBA Display Mode......Page 242
Color-Index Display Mode......Page 244
Choosing between RGBA and Color-Index Mode......Page 246
Specifying a Color and a Shading Model......Page 247
Specifying a Color in RGBA Mode......Page 248
Specifying a Color in Color-Index Mode......Page 250
Specifying a Shading Model......Page 251
5. Lighting......Page 254
A Hidden-Surface Removal Survival Kit......Page 256
Real-World and OpenGL Lighting......Page 258
Ambient, Diffuse, Specular, and Emissive Light......Page 259
RGB Values for Lights and Materials......Page 260
A Simple Example: Rendering a Lit Sphere......Page 261
Creating Light Sources......Page 265
Color......Page 267
Position and Attenuation......Page 268
Spotlights......Page 270
Multiple Lights......Page 271
Selecting a Lighting Model......Page 278
Global Ambient Light......Page 279
Two-Sided Lighting......Page 280
Secondary Specular Color......Page 281
Defining Material Properties......Page 282
Diffuse and Ambient Reflection......Page 284
Emission......Page 285
Changing Material Properties......Page 286
Color Material Mode......Page 288
The Mathematics of Lighting......Page 291
Material Emission......Page 292
Contributions from Light Sources......Page 293
Putting It All Together......Page 295
Secondary Specular Color......Page 296
Lighting in Color-Index Mode......Page 297
The Mathematics of Color-Index Mode Lighting......Page 298
6. Blending, Antialiasing, Fog, and Polygon Offset......Page 300
Blending......Page 302
The Source and Destination Factors......Page 303
Combining Pixels Using Blending Equations......Page 306
Sample Uses of Blending......Page 309
A Blending Example......Page 311
Three-Dimensional Blending with the Depth Buffer......Page 314
Antialiasing......Page 318
Antialiasing Points or Lines......Page 320
Antialiasing Geometric Primitives with Multisampling......Page 326
Antialiasing Polygons......Page 330
Fog......Page 331
Using Fog......Page 332
Fog Equations......Page 335
Point Parameters......Page 342
Polygon Offset......Page 344
7. Display Lists......Page 348
Why Use Display Lists?......Page 349
An Example of Using a Display List......Page 350
Display List Design Philosophy......Page 353
Creating and Executing a Display List......Page 356
Naming and Creating a Display List......Page 357
What's Stored in a Display List?......Page 358
Executing a Display List......Page 360
Hierarchical Display Lists......Page 361
Managing Display List Indices......Page 362
Executing Multiple Display Lists......Page 363
Managing State Variables with Display Lists......Page 369
Encapsulating Mode Changes......Page 370
8. Drawing Pixels, Bitmaps, Fonts, and Images......Page 372
Bitmaps and Fonts......Page 374
The Current Raster Position......Page 376
Drawing the Bitmap......Page 378
Choosing a Color for the Bitmap......Page 379
Fonts and Display Lists......Page 380
Defining and Using a Complete Font......Page 382
Reading, Writing, and Copying Pixel Data......Page 384
Imaging Pipeline......Page 394
Pixel Packing and Unpacking......Page 397
Controlling Pixel-Storage Modes......Page 398
Pixel-Transfer Operations......Page 402
Pixel Mapping......Page 405
Magnifying, Reducing, or Flipping an Image......Page 407
The Pixel Rectangle Drawing Process......Page 410
Using Buffer Objects with Pixel Rectangle Data......Page 413
Using Buffer Objects to Transfer Pixel Data......Page 414
Using Buffer Objects to Retrieve Pixel Data......Page 416
Tips for Improving Pixel Drawing Rates......Page 417
Imaging Subset......Page 418
Color Tables......Page 420
Convolutions......Page 425
Color Matrix......Page 433
Histogram......Page 434
Minmax......Page 438
9. Texture Mapping......Page 440
Steps in Texture Mapping......Page 446
A Sample Program......Page 448
Specifying the Texture......Page 451
Texture Proxy......Page 457
Replacing All or Part of a Texture Image......Page 459
One-Dimensional Textures......Page 463
Three-Dimensional Textures......Page 465
Texture Arrays......Page 470
Compressed Texture Images......Page 471
Mipmaps: Multiple Levels of Detail......Page 474
Filtering......Page 485
Texture Objects......Page 488
Creating and Using Texture Objects......Page 489
Cleaning Up Texture Objects......Page 492
A Working Set of Resident Textures......Page 493
Texture Functions......Page 495
Assigning Texture Coordinates......Page 499
Computing Appropriate Texture Coordinates......Page 501
Repeating and Clamping Textures......Page 503
Automatic Texture-Coordinate Generation......Page 508
Creating Contours......Page 509
Sphere Map......Page 514
Cube Map Textures......Page 516
Multitexturing......Page 518
Texture Combiner Functions......Page 523
The Interpolation Combiner Function......Page 528
Secondary Color When Lighting Is Disabled......Page 529
Point Sprites......Page 530
The Texture Matrix Stack......Page 532
Creating a Shadow Map......Page 534
Generating Texture Coordinates and Rendering......Page 536
10. The Framebuffer......Page 540
Buffers and Their Uses......Page 543
Color Buffers......Page 544
Clearing Buffers......Page 546
Selecting Color Buffers for Writing and Reading......Page 548
Masking Buffers......Page 550
Testing and Operating on Fragments......Page 552
Alpha Test......Page 553
Stencil Test......Page 555
Depth Test......Page 561
Occlusion Query......Page 562
Conditional Rendering......Page 565
Blending, Dithering, and Logical Operations......Page 566
The Accumulation Buffer......Page 569
Depth of Field......Page 571
Jittering......Page 576
Framebuffer Objects......Page 577
Renderbuffers......Page 580
Copying Pixel Rectangles......Page 590
11. Tessellators and Quadrics......Page 592
Polygon Tessellation......Page 593
Tessellation Callback Routines......Page 595
Tessellation Properties......Page 600
Polygon Definition......Page 605
Describing GLU Errors......Page 608
Backward Compatibility......Page 609
Quadrics: Rendering Spheres, Cylinders, and Disks......Page 610
Managing Quadrics Objects......Page 611
Controlling Quadrics Attributes......Page 612
Quadrics Primitives......Page 614
12. Evaluators and NURBS......Page 620
Prerequisites......Page 622
One-Dimensional Evaluators......Page 623
Two-Dimensional Evaluators......Page 629
Using Evaluators for Textures......Page 635
The GLU NURBS Interface......Page 637
A Simple NURBS Example......Page 638
Managing a NURBS Object......Page 642
Creating a NURBS Curve or Surface......Page 646
Trimming a NURBS Surface......Page 652
13. Selection and Feedback......Page 656
Selection......Page 657
The Basic Steps......Page 658
Creating the Name Stack......Page 659
The Hit Record......Page 661
A Selection Example......Page 662
Picking......Page 665
Hints for Writing a Program That Uses Selection......Page 676
Feedback......Page 678
The Feedback Array......Page 680
A Feedback Example......Page 681
14. Now That You Know......Page 686
Error Handling......Page 688
Which Version Am I Using?......Page 690
Extensions to the Standard......Page 692
Extensions to the Standard for Microsoft Windows (WGL)......Page 694
Cheesy Translucency......Page 695
An Easy Fade Effect......Page 696
Object Selection Using the Back Buffer......Page 697
Cheap Image Transformation......Page 698
Displaying Layers......Page 700
Antialiased Characters......Page 701
Making Decals......Page 704
Drawing Filled, Concave Polygons Using the Stencil Buffer......Page 706
Finding Interference Regions......Page 707
Shadows......Page 709
Hidden-Line Removal with Polygon Offset......Page 710
Hidden-Line Removal with the Stencil Buffer......Page 711
Texture Mapping Applications......Page 712
Dirichlet Domains......Page 713
Life in the Stencil Buffer......Page 715
Alternative Uses for glDrawPixels() and glCopyPixels()......Page 716
15. The OpenGL Shading Language......Page 718
The OpenGL Graphics Pipeline and Programmable Shading......Page 719
Vertex Processing......Page 721
Fragment Processing......Page 722
A Sample Shader......Page 723
OpenGL / GLSL Interface......Page 724
The Starting Point......Page 732
Declaring Variables......Page 733
Aggregate Types......Page 735
Uniform Blocks......Page 743
Specifying Uniform Variables Blocks in Shaders......Page 744
Accessing Uniform Blocks from Your Application......Page 746
Computational Invariance......Page 752
Statements......Page 753
Functions......Page 757
Accessing Texture Maps in Shaders......Page 758
Shader Preprocessor......Page 762
Macro Definition......Page 763
Compiler Control......Page 764
Extension Processing in Shaders......Page 765
Vertex Shader Specifics......Page 766
Transform Feedback......Page 773
Fragment Shader Specifics......Page 778
Rendering to Multiple Output Buffers......Page 780
A. Basics of GLUT: The OpenGL Utility Toolkit......Page 782
Initializing and Creating a Window......Page 783
Handling Window and Input Events......Page 784
Initializing and Drawing Three-Dimensional Objects......Page 786
Managing a Background Process......Page 787
Running the Program......Page 788
B. State Variables......Page 790
The Query Commands......Page 791
OpenGL State Variables......Page 794
Current Values and Associated Data......Page 795
Vertex Array Object State......Page 797
Transformation......Page 804
Coloring......Page 806
Lighting......Page 807
Rasterization......Page 809
Multisampling......Page 811
Texturing......Page 812
Pixel Operations......Page 819
Framebuffer Control......Page 822
Framebuffer Object State......Page 823
Renderbuffer Object State......Page 826
Pixels......Page 827
Evaluators......Page 834
Shader Object State......Page 835
Program Object State......Page 836
Transform Feedback State......Page 840
Hints......Page 842
Implementation-Dependent Values......Page 843
Miscellaneous......Page 851
C. Homogeneous Coordinates and Transformation Matrices......Page 854
Transforming Vertices......Page 855
Transformation Matrices......Page 856
Rotation......Page 857
Perspective Projection......Page 858
Orthographic Projection......Page 859
D. OpenGL and Window Systems......Page 860
Accessing New OpenGL Functions......Page 861
GLEW: The OpenGL Extension Wrangler......Page 862
GLX: OpenGL Extension for the X Window System......Page 863
Initialization......Page 864
Controlling Rendering......Page 865
GLX Prototypes......Page 867
AGL: OpenGL Extensions for the Apple Macintosh......Page 870
Managing an OpenGL Rendering Context......Page 871
Updating the Rendering Buffers......Page 872
AGL Prototypes......Page 873
WGL: OpenGL Extension for Microsoft Windows 95/98/NT/ME/2000/XP......Page 875
Controlling Rendering......Page 876
WGL Prototypes......Page 878
A......Page 882
B......Page 883
C......Page 884
D......Page 887
E......Page 889
F......Page 890
G......Page 891
H......Page 892
I......Page 893
L......Page 895
M......Page 896
N......Page 897
P......Page 898
R......Page 900
S......Page 901
T......Page 903
U......Page 904
W......Page 905
X......Page 906
A......Page 908
B......Page 909
C......Page 910
D......Page 911
F......Page 913
G......Page 914
H......Page 922
L......Page 923
M......Page 924
N......Page 925
P......Page 926
R......Page 929
S......Page 930
T......Page 931
V......Page 934
W......Page 935
Z......Page 936
E. Order of Operations......Page 938
F. Programming Tips......Page 946
G. OpenGL Invariance......Page 954
H. Calculating Normal Vectors......Page 958
I. Built-In OpenGL Shading Language Variables and Functions......Page 964
J. Floating-Point Formats for Textures, Framebuffers, and Renderbuffers......Page 1002
K. RGTC Compressed Texture Format......Page 1010
L. std140 Uniform Buffer Layout......Page 1016