Table of Contents
Authors ix
Chapter 1 Introduction to Computer Graphics 1
1.1 Core Concepts and Vocabulary 2
1.2 The Graphics Pipeline 8
1.2.1 Application Stage 9
1.2.2 Geometry Processing 10
1.2.3 Rasterization 12
1.2.4 Pixel Processing 14
1.3 Setting Up a Development Environment 17
1.3.1 Installing Python 17
1.3.2 Python Packages 19
1.3.3 Sublime Text 21
1.4 Summary and Next Steps 23
Chapter 2 Introduction to Pygame and OpenGL 25
2.1 Creating Windows with Pygame 25
2.2 Drawing a Point 32
2.2.1 OpenGL Shading Language 32
2.2.2 Compiling GPU Programs 36
2.2.3 Rendering in the Application 42
2.3 Drawing Shapes 46
2.3.1 Using Vertex Buffers 46
2.3.2 An Attribute Class 49
2.3.3 Hexagons, Triangles, and Squares 51
2.3.4 Passing Data between Shaders 59
2.4 Working with Uniform Data 64
2.4.1 Introduction to Uniforms 64
2.4.2 A Uniform Class 65
2.4.3 Applications and Animations 67
2.5 Adding Interactivity 77
2.5.1 Keyboard Input with Pygame 77
2.5.2 Incorporating with Graphics Programs 80
2.6 Summary and Next Steps 81
Chapter 3 Matrix Algebra and Transformations 83
3.1 Introduction to Vectors and Matrices 83
3.1.1 Vector Definitions and Operations 84
3.1.2 Linear Transformations and Matrices 88
3.1.3 Vectors and Matrices in Higher Dimensions 98
3.2 Geometric Transformations 102
3.2.1 Scaling 102
3.2.2 Rotation 103
3.2.3 Translation 109
3.2.4 Projections 112
3.2.5 Local Transformations 119
3.3 A Matrix Class 123
3.4 Incorporating with Graphics Programs 125
3.5 Summary and Next Steps 132
Chapter 4 A Scene Graph Framework 133
4.1 Overview of Class Structure 136
4.2 3D Objects 138
4.2.1 Scene and Group 141
4.2.2 Camera 142
4.2.3 Mesh 143
4.3 Geometry Objects 144
4.3.1 Rectangles 145
4.3.2 Boxes 147
4.3.3 Polygons 150
4.3.4 Parametric Surfaces and Planes 153
4.3.5 Spheres and Related Surfaces 156
4.3.6 Cylinders and Related Surfaces 158
4.4 Material Objects 164
4.4.1 Base Class 165
4.4.2 Basic Materials 166
4.5 Rendering Scenes with the Framework 172
4.6 Custom Geometry and Material Objects 177
4.7 Extra Components 184
4.7.1 Axes and Grids 185
4.7.2 Movement Rig 188
4.8 Summary and Next Steps 192
Chapter 5 Textures 193
5.1 A Texture Class 194
5.2 Texture Coordinates 201
5.2.1 Rectangles 202
5.2.2 Boxes 202
5.2.3 Polygons 203
5.2.4 Parametric Surfaces 204
5.3 Using Textures in Shaders 206
5.4 Rendering Scenes with Textures 212
5.5 Animated Effects with Custom Shaders 215
5.6 Procedurally Generated Textures 221
5.7 Using Text in Scenes 228
5.7.1 Rendering Text Images 228
5.7.2 Billboarding 232
5.7.2.1 Look-At Matrix 232
5.7.2.2 Sprite Material 236
5.7.3 Heads-Up Displays and Orthogonal Cameras 241
5.8 Rendering Scenes to Textures 247
5.9 Postprocessing 254
5.10 Summary and Next Steps 265
Chapter 6 Light and Shadow 267
6.1 Introduction to Lighting 268
6.2 Light Classes 271
6.3 Normal Vectors 274
6.3.1 Rectangles 274
6.3.2 Boxes 275
6.3.3 Polygons 276
6.3.4 Parametric Surfaces 276
6.4 Using Lights in Shaders 280
6.4.1 Structs and Uniforms 280
6.4.2 Light-Based Materials 282
6.5 Rendering Scenes with Lights 291
6.6 Extra Components 295
6.7 Bump Mapping 298
6.8 Bloom and Glow Effects 302
6.9 Shadows 312
6.9.1 Theoretical Background 312
6.9.2 Adding Shadows to the Framework 317
6.10 Summary and Next Steps 328
Index 331