OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.5 with SPIR-V

John Kessenich / Graham Sellers / Dave Shreiner  
Total pages
July 2016
Related Titles

Product detail

Product Price CHF Available  
OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.5 with SPIR-V
66.30 approx. 7-9 days


OpenGL® Programming Guide, Ninth Edition, provides clear explanations of OpenGL functionality and techniques, including processing geometric objects with vertex, tessellation, and geometry shaders using geometric transformations and viewing matrices; working with pixels and texture maps through fragment shaders; and advanced data techniques using framebuffer objects and compute shaders.


  • Authoritative, trusted OpenGL 4.5 coverage: the latest book in the official Open Graphics Library, written by members of the Khronos OpenGL standards committees
  • Responds to developers' requests with extensive, up-to-date coverage of shaders, the part of the OpenGL spec that has changed the most
  • Contains extensive new text and code, replacing coverage of deprecated features

New to this Edition

Previous book only went through OpenGL version 4.3, but, OpenGL has added 4.4, 4.5, SPIR-V, and extensions. This new (and final) update will incorporate all of these changes.

Table of Contents

Figures xxi

Tables xxvii

Examples xxxi

About This Guide xxxix

Acknowledgments xlv


Chapter 1: Introduction to OpenGL 1

What Is OpenGL? 2

Your First Look at an OpenGL Program 4

OpenGL Syntax 8

OpenGL’s Rendering Pipeline 10

Our First Program: A Detailed Discussion 14


Chapter 2: Shader Fundamentals 33

Shaders and OpenGL 34

OpenGL’s Programmable Pipeline 35

An Overview of the OpenGL Shading Language 37

Interface Blocks 61

Compiling Shaders 72

Shader Subroutines 79

Separate Shader Objects 84



Chapter 3: Drawing with OpenGL 95

OpenGL Graphics Primitives 96

Data in OpenGL Buffers 102

Vertex Specification 117

OpenGL Drawing Commands 124


Chapter 4: Color, Pixels, and Fragments 151

Basic Color Theory 152

Buffers and Their Uses 154

Color and OpenGL 158

Testing and Operating on Fragments 163

Multisampling 185

Per-Primitive Antialiasing 188

Reading and Copying Pixel Data 191

Copying Pixel Rectangles 193


Chapter 5: Viewing Transformations, Culling, Clipping, and Feedback 197

Viewing 198

User Transformations 203

OpenGL Transformations 226

Transform Feedback 231


Chapter 6: Textures and Framebuffers 255

Introduction to Texturing 257

Basic Texture Types 258

Creating and Initializing Textures 260

Specifying Texture Data 265

Texture Formats 279

Compressed Textures 285

Sampler Objects 288

Using Textures 291

Complex Texture Types 302

Texture Views 317

Filtering 321

Bindless Textures 337

Sparse Textures 341

Point Sprites 344

Framebuffer Objects 348

Rendering to Texture Maps 351

Chapter Summary 370


Chapter 7: Light and Shadow 373

Lighting Introduction 374

Classic Lighting Model 375

Advanced Lighting Models 399

Shadow Mapping 413


Chapter 8: Procedural Texturing 423

Procedural Texturing 424

Bump Mapping 444

Antialiasing Procedural Textures 454

Noise 472

Further Information 495


Chapter 9: Tessellation Shaders 497

Tessellation Shaders 498

Tessellation Patches 499

Tessellation Control Shaders 500

Tessellation Evaluation Shaders 508

A Tessellation Example: The Teapot 512

Additional Tessellation Techniques 516


Chapter 10: Geometry Shaders 521

Creating a Geometry Shader 523

Geometry Shader Inputs and Outputs 526

Producing Primitives 537

Advanced Transform Feedback 544

Geometry Shader Instancing 561

Multiple Viewports and Layered Rendering 562

Chapter Summary 572


Chapter 11: Memory 577

Using Textures for Generic Data Storage 578

Shader Storage Buffer Objects 589

Atomic Operations and Synchronization 591

Example: Order-Independent Transparency 621


Chapter 12: Compute Shaders 635

Overview 636

Workgroups and Dispatch 637

Communication and Synchronization 644

Examples 648

Chapter Summary 659


Appendix A: Support Libraries 663

Basics of GLFW: The OpenGL Utility Framework 664

Initializing and Creating a Window 664

Handling User Input 667

Controlling the Window 671

Shutting Down Cleanly 675

GL3W: OpenGL Glue 676


Appendix B: OpenGL ES and WebGL 679

OpenGL ES 680

WebGL 682


Appendix C: Built-in GLSL Variables and Functions 693

Built-in Variables 693

Built-in Constants 705

Built-in Functions 707


Appendix D: State Variables 757

The Query Commands 757

OpenGL State Variables 765


Appendix E: Homogeneous Coordinates and Transformation Matrices 849

Homogeneous Coordinates 849

Transformation Matrices 851


Appendix F: Floating-Point Formats for Textures, Framebuffers, and Renderbuffers 855

Reduced-Precision Floating-Point Values 855

16-Bit Floating-Point Values 856

10- and 11-Bit Unsigned Floating-Point Values 858


Appendix G: Debugging and Profiling OpenGL 863

Creating a Debug Context 863

Debug Output 866

Debug Groups 874

Profiling 877


Appendix H: Buffer Object Layouts 883

Using Standard Layout Qualifiers 883

The std140 Layout Rules 884

The std430 Layout Rules 885


Glossary 887

Index 917


John M. Kessenich, staff software engineer at Google and creator of SPIR-V, has been active in OpenGL and GLSL Khronos standards’ development since 1999. He is the primary editor of the SPIR-V and GLSL specifications, and creates shader compiler tools and translators to promote portability of those standards.


Graham Sellers, AMD Software Architect and Engineering Fellow, is a Khronos API lead and represents AMD at the OpenGL ARB. He has contributed to the core Vulkan and OpenGL specs and extensions, and holds several graphics and image processing patents.


Dave Shreiner is a twenty-five year veteran of the computer graphics industry, where he’s worked almost exclusively with programming interfaces like OpenGL. In addition to having written and taught instructional courses on using computer graphics APIs, he was also the lead author for almost ten years on several Addison-Wesley publications relating to computer graphics.

Reader Review(s)

Praise for previous editions of OpenGL® Programming Guide


“Wow! This book is basically one-stop shopping for OpenGL information. It is the kind of book that I will be reaching for a lot. Thanks to Dave, Graham, John, and Bill for an amazing effort.”

—Mike Bailey, professor, Oregon State University


“The most recent Red Book parallels the grand tradition of OpenGL; continuous evolution towards ever-greater power and efficiency. The eighth edition contains up-to-the minute information about the latest standard and new features, along with a solid grounding in modern OpenGL techniques that will work anywhere. The Red Book continues to be an essential reference for all new employees at my simulation company. What else can be said about this essential guide? I laughed, I cried, it was much better than Cats—I’ll read it again and again.”

—Bob Kuehne, president, Blue Newt Software


“OpenGL has undergone enormous changes since its inception twenty years ago. This new edition is your practical guide to using the OpenGL of today. Modern OpenGL is centered on the use of shaders, and this edition of the Programming Guide jumps right in, with shaders covered in depth in Chapter 2. It continues in later chapters with even more specifics on everything from texturing to compute shaders. No matter how well you know it or how long you’ve been doing it, if you are going to write an OpenGL program, you want to have a copy of the OpenGL® Programming Guide handy.”

—Marc Olano, associate professor, UMBC


“If you are looking for the definitive guide to programming with the very latest version of OpenGL, look no further. The authors of this book have been deeply involved in the creation of OpenGL 4.3, and everything you need to know about the cutting edge of this industry-leading API is laid out here in a clear, logical, and insightful manner.”

—Neil Trevett, president, Khronos Group