O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Game Programming in C++: Creating 3D Games, First edition

Book Description

You can program games in many languages, but C++ remains the key language used by many leading development studios. Since it’s the language used in their enormous code bases, it’s the language they need to maintain and improve their games, and look for most often when hiring new developers. Game Programming in C++ is today’s practical, hands-on approach to programming 3D video games in C++. Drawing on the author’s pioneering experience teaching game development at USC, it guides you through all key concepts hands-on, and helps you deepen your expertise through several start-to-finish, in-depth game projects.

Author Sanjay Madhav introduces core concepts one at a time, in an easy-to-digest fashion, paying special attention to the math that professional game developers need to know. Step by step, you’ll become increasingly comfortable with real-world C++ game development, and learn how to use C++ in all facets of game programming, including graphics, physics, AI, audio, camera systems, animations, and more.

Table of Contents

  1. Cover Page
  2. About This E-Book
  3. Title Page
  4. Copyright Page
  5. Dedication Page
  6. Contents at a Glance
  7. Contents
  8. Preface
  9. Acknowledgments
  10. About the Author
  11. Chapter 1: Game Programming Overview
    1. Setting Up a Development Environment
      1. Microsoft Windows
      2. Apple macOS
    2. Getting This Book’s Source Code
    3. Beyond the C++ Standard Library
    4. The Game Loop and Game Class
      1. Anatomy of a Frame
      2. Implementing a Skeleton Game Class
      3. Main Function
      4. Basic Input Processing
    5. Basic 2D Graphics
      1. The Color Buffer
      2. Double Buffering
      3. Implementing Basic 2D Graphics
      4. Drawing Walls, a Ball, and a Paddle
    6. Updating the Game
      1. Real Time and Game Time
      2. Logic as a Function of Delta Time
      3. Updating the Paddle’s Position
      4. Updating the Ball’s Position
    7. Game Project
    8. Summary
    9. Additional Reading
    10. Exercises
      1. Exercise 1.1
      2. Exercise 1.2
  12. Chapter 2: Game Objects and 2D Graphics
    1. Game Objects
      1. Types of Game Objects
      2. Game Object Models
      3. Integrating Game Objects into the Game Loop
    2. Sprites
      1. Loading Image Files
      2. Drawing Sprites
      3. Animating Sprites
    3. Scrolling Backgrounds
    4. Game Project
    5. Summary
    6. Additional Reading
    7. Exercises
      1. Exercise 2.1
      2. Exercise 2.2
      3. Exercise 2.3
  13. Chapter 3: Vectors and Basic Physics
    1. Vectors
      1. Getting a Vector between Two Points: Subtraction
      2. Scaling a Vector: Scalar Multiplication
      3. Combining Two Vectors: Addition
      4. Determining a Distance: Length
      5. Determining Directions: Unit Vectors and Normalization
      6. Converting from an Angle to a Forward Vector
      7. Converting a Forward Vector to an Angle: Arctangent
      8. Determining the Angle between Two Vectors: Dot Product
      9. Calculating a Normal: Cross Product
    2. Basic Movement
      1. Creating a Basic MoveComponent Class
      2. Creating an InputComponent Class
    3. Newtonian Physics
      1. Linear Mechanics Overview
      2. Computing Positions with Euler Integration
      3. Issues with Variable Time Steps
    4. Basic Collision Detection
      1. Circle-Versus-Circle Intersection
      2. Creating a CircleComponent Subclass
    5. Game Project
    6. Summary
    7. Additional Reading
    8. Exercises
      1. Exercise 3.1
      2. Exercise 3.2
      3. Exercise 3.3
  14. Chapter 4: Artificial Intelligence
    1. State Machine Behaviors
      1. Designing a State Machine
      2. Basic State Machine Implementation
      3. States as Classes
    2. Pathfinding
      1. Graphs
      2. Breadth-First Search
      3. Heuristics
      4. Greedy Best-First Search
      5. A* Search
      6. Dijkstra’s Algorithm
      7. Following a Path
      8. Other Graph Representations
    3. Game Trees
      1. Minimax
      2. Handling Incomplete Game Trees
      3. Alpha-Beta Pruning
    4. Game Project
    5. Summary
    6. Additional Reading
    7. Exercises
      1. Exercise 4.1
      2. Exercise 4.2
  15. Chapter 5: OpenGL
    1. Initializing OpenGL
      1. Setting Up the OpenGL Window
      2. The OpenGL Context and Initializing GLEW
      3. Rendering a Frame
    2. Triangle Basics
      1. Why Polygons?
      2. Normalized Device Coordinates
      3. Vertex and Index Buffers
    3. Shaders
      1. Vertex Shaders
      2. Fragment Shaders
      3. Writing Basic Shaders
      4. Loading Shaders
      5. Drawing Triangles
    4. Transformation Basics
      1. Object Space
      2. World Space
      3. Transforming to World Space
    5. Matrices and Transformations
      1. Matrix Multiplication
      2. Transforming a Point by Using a Matrix
      3. Transforming to World Space, Revisited
      4. Adding World Transforms to Actor
      5. Transforming from World Space to Clip Space
      6. Updating Shaders to Use Transform Matrices
    6. Texture Mapping
      1. Loading the Texture
      2. Updating the Vertex Format
      3. Updating the Shaders
      4. Alpha Blending
    7. Game Project
    8. Summary
    9. Additional Reading
    10. Exercises
      1. Exercise 5.1
      2. Exercise 5.2
  16. Chapter 6: 3D Graphics
    1. The Actor Transform in 3D
      1. Transform Matrices for 3D
      2. Euler Angles
      3. Quaternions
      4. New Actor Transform in Action
    2. Loading 3D Models
      1. Choosing a Model Format
      2. Updating the Vertex Attributes
      3. Loading a gpmesh File
    3. Drawing 3D Meshes
      1. Transforming to Clip Space, Revisited
      2. Out with the Painter’s Algorithm, in with Z-Buffering
      3. The BasicMesh Shader
      4. The MeshComponent Class
    4. Lighting
      1. Revisiting Vertex Attributes
      2. Types of Lights
      3. Phong Reflection Model
      4. Implementing Lighting
    5. Game Project
    6. Summary
    7. Additional Reading
    8. Exercises
      1. Exercise 6.1
      2. Exercise 6.2
  17. Chapter 7: Audio
    1. Bootstrapping Audio
      1. FMOD
      2. Installing FMOD
      3. Creating an Audio System
      4. Banks and Events
      5. The SoundEvent Class
    2. 3D Positional Audio
      1. Setting Up a Basic Listener
      2. Adding Positional Functionality to SoundEvent
      3. Creating an AudioComponent to Associate Actors with Sound Events
      4. The Listener in a Third-Person Game
      5. The Doppler Effect
    3. Mixing and Effects
      1. Buses
      2. Snapshots
      3. Occlusion
    4. Game Project
    5. Summary
    6. Additional Reading
    7. Exercises
      1. Exercise 7.1
      2. Exercise 7.2
  18. Chapter 8: Input Systems
    1. Input Devices
      1. Polling
      2. Positive and Negative Edges
      3. Events
      4. Basic InputSystem Architecture
    2. Keyboard Input
    3. Mouse Input
      1. Buttons and Position
      2. Relative Motion
      3. Scroll Wheel
    4. Controller Input
      1. Enabling a Single Controller
      2. Buttons
      3. Analog Sticks and Triggers
      4. Filtering Analog Sticks in Two Dimensions
      5. Supporting Multiple Controllers
    5. Input Mappings
    6. Game Project
    7. Summary
    8. Additional Reading
    9. Exercises
      1. Exercise 8.1
      2. Exercise 8.2
  19. Chapter 9: Cameras
    1. First-Person Camera
      1. Basic First-Person Movement
      2. Camera (Without Pitch)
      3. Adding Pitch
      4. First-Person Model
    2. Follow Camera
      1. Basic Follow Camera
      2. Adding a Spring
    3. Orbit Camera
    4. Spline Camera
    5. Unprojection
    6. Game Project
    7. Summary
    8. Additional Reading
    9. Exercises
      1. Exercise 9.1
      2. Exercise 9.2
  20. Chapter 10: Collision Detection
    1. Geometric Types
      1. Line Segments
      2. Planes
      3. Bounding Volumes
    2. Intersection Tests
      1. Contains Point Tests
      2. Bounding Volume Tests
      3. Line Segment Tests
      4. Dynamic Objects
    3. Adding Collisions to Game Code
      1. The BoxComponent Class
      2. The PhysWorld Class
      3. Ball Collisions with SegmentCast
      4. Testing Box Collisions in PhysWorld
      5. Player Collision Against the Walls
    4. Game Project
    5. Summary
    6. Additional Reading
    7. Exercises
      1. Exercise 10.1
      2. Exercise 10.2
      3. Exercise 10.3
  21. Chapter 11: User Interfaces
    1. Font Rendering
    2. UI Screens
      1. The UI Screen Stack
      2. The Pause Menu
      3. Buttons
      4. Dialog Boxes
    3. HUD Elements
      1. Adding an Aiming Reticule
      2. Adding Radar
    4. Localization
      1. Working with Unicode
      2. Adding a Text Map
      3. Other Localization Concerns
    5. Supporting Multiple Resolutions
    6. Game Project
    7. Summary
    8. Additional Reading
    9. Exercises
      1. Exercise 11.1
      2. Exercise 11.2
      3. Exercise 11.3
  22. Chapter 12: Skeletal Animation
    1. Foundations of Skeletal Animation
      1. Skeletons and Poses
      2. The Inverse Bind Pose Matrix
      3. Animation Data
      4. Skinning
    2. Implementing Skeletal Animation
      1. Drawing with Skinning Vertex Attributes
      2. Loading a Skeleton
      3. Loading the Animation Data
      4. The Skinning Vertex Shader
      5. Updating Animations
    3. Game Project
    4. Summary
    5. Additional Reading
    6. Exercises
      1. Exercise 12.1
      2. Exercise 12.2
  23. Chapter 13: Intermediate Graphics
    1. Improving Texture Quality
      1. Texture Sampling, Revisited
      2. Mipmapping
      3. Anisotropic Filtering
    2. Rendering to Textures
      1. Creating the Texture
      2. Creating a Framebuffer Object
      3. Rendering to a Framebuffer Object
      4. Drawing the Mirror Texture in the HUD
    3. Deferred Shading
      1. Creating a G-Buffer Class
      2. Writing to the G-buffer
      3. Global Lighting
      4. Adding Point Lights
      5. Improvements and Issues
    4. Game Project
    5. Summary
    6. Additional Reading
    7. Exercises
      1. Exercise 13.1
      2. Exercise 13.2
  24. Chapter 14: Level Files and Binary Data
    1. Level File Loading
      1. Loading Global Properties
      2. Loading Actors
      3. Loading Components
    2. Saving Level Files
      1. Saving Global Properties
      2. Saving Actors and Components
    3. Binary Data
      1. Saving a Binary Mesh File
      2. Loading a Binary Mesh File
    4. Game Project
    5. Summary
    6. Additional Reading
    7. Exercises
      1. Exercise 14.1
      2. Exercise 14.2
  25. Appendix A: Intermediate C++ Review
  26. Index