Contents

Preface

Intended Audience

How to Use This Book

Acknowledgments

About the Authors

Chapter 1 Getting Started

1.1Languages and Libraries

1.1.1C++

1.1.2OpenGL / GLSL

1.1.3Window Management

1.1.4Extension Library

1.1.5Math Library

1.1.6Texture Management

1.1.7Optional Libraries

1.2Installation and Configuration

Chapter 2 The OpenGL Graphics Pipeline

2.1The OpenGL Pipeline

2.1.1C++/OpenGL Application

2.1.2Vertex and Fragment Shaders

2.1.3Tessellation

2.1.4Geometry Shader

2.1.5Rasterization

2.1.6Fragment Shader

2.1.7Pixel Operations

2.2Detecting OpenGL and GLSL Errors

2.3Reading GLSL Source Code from Files

2.4Building Objects from Vertices

2.5Animating a Scene

2.6Organizing the C++ Code Files

Chapter 3 Mathematical Foundations

3.13D Coordinate Systems

3.2Points

3.3Matrices

3.4Transformation Matrices

3.4.1Translation

3.4.2Scaling

3.4.3Rotation

3.5Vectors

3.5.1Uses for Dot Product

3.5.2Uses for Cross Product

3.6Local and World Space

3.7Eye Space and the Synthetic Camera

3.8Projection Matrices

3.8.1The Perspective Projection Matrix

3.8.2The Orthographic Projection Matrix

3.9Look-At Matrix

3.10GLSL Functions for Building Matrix Transforms

Chapter 4 Managing 3D Graphics Data

4.1Buffers and Vertex Attributes

4.2Uniform Variables

4.3Interpolation of Vertex Attributes

4.4Model-View and Perspective Matrices

4.5Our First 3D Program – a 3D Cube

4.6Rendering Multiple Copies of an Object

4.6.1Instancing

4.7Rendering Multiple Different Models in a Scene

4.8Matrix Stacks

4.9Combating “Z-Fighting” Artifacts

4.10Other Options for Primitives

4.11Coding for Performance

4.11.1Minimizing Dynamic Memory Allocation

4.11.2Pre-Computing the Perspective Matrix

4.11.3Back-Face Culling

Chapter 5 Texture Mapping

5.1Loading Texture Image Files

5.2Texture Coordinates

5.3Creating a Texture Object

5.4Constructing Texture Coordinates

5.5Loading Texture Coordinates into Buffers

5.6Using the Texture in a Shader: Sampler Variables and Texture Units

5.7Texture Mapping: Example Program

5.8Mipmapping

5.9Anisotropic Filtering

5.10Wrapping and Tiling

5.11Perspective Distortion

5.12Textures – Additional OpenGL Details

Chapter 6 3D Models

6.1Procedural Models – Building a Sphere

6.2OpenGL Indexing – Building a Torus

6.2.1The Torus

6.2.2Indexing in OpenGL

6.3Loading Externally Produced Models

Chapter 7 Lighting

7.1Lighting Models

7.2Lights

7.3Materials

7.4ADS Lighting Computations

7.5Implementing ADS Lighting

7.5.1Gouraud Shading

7.5.2Phong Shading

7.6Combining Lighting and Textures

Chapter 8 Shadows

8.1The Importance of Shadows

8.2Projective Shadows

8.3Shadow Volumes

8.4Shadow Mapping

8.4.1Shadow Mapping (PASS ONE) – “Draw” Objects from Light Position

8.4.2Shadow Mapping (Intermediate Step) – Copying the Z-Buffer to a Texture

8.4.3Shadow Mapping (PASS TWO) – Rendering the Scene with Shadows

8.5A Shadow Mapping Example

8.6Shadow Mapping Artifacts

8.7Soft Shadows

8.7.1Soft Shadows in the Real World

8.7.2Generating Soft Shadows – Percentage Closer Filtering (PCF)

8.7.3A Soft Shadow/PCF Program

Chapter 9 Sky and Backgrounds

9.1Skyboxes

9.2Skydomes

9.3Implementing a Skybox

9.3.1Building a Skybox from Scratch

9.3.2Using OpenGL Cube Maps

9.4Environment Mapping

Chapter 10 Enhancing Surface Detail

10.1Bump Mapping

10.2Normal Mapping

10.3Height Mapping

Chapter 11 Parametric Surfaces

11.1Quadratic Bézier Curves

11.2Cubic Bézier Curves

11.3Quadratic Bézier Surfaces

11.4Cubic Bézier Surfaces

Chapter 12 Tessellation

12.1Tessellation in OpenGL

12.2Tessellation for Bézier Surfaces

12.3Tessellation for Terrain / Height Maps

12.4Controlling Level of Detail (LOD)

Chapter 13 Geometry Shaders

13.1Per-Primitive Processing in OpenGL

13.2Altering Primitives

13.3Deleting Primitives

13.4Adding Primitives

13.5Changing Primitive Types

Chapter 14 Other Techniques

14.1 Fog

14.2Compositing / Blending / Transparency

14.3User-Defined Clipping Planes

14.43D Textures

14.5Noise

14.6Noise Application – Marble

14.7Noise Application – Wood

14.8Noise Application – Clouds

14.9Noise Application – Special Effects

Appendix A Installation and Setup for PC (Windows)

Appendix B Installation and Setup for Macintosh

Appendix C Using the Nsight Graphics Debugger

Index