About This E-Book
EPUB is an open, industry-standard format for e-books. However, support for EPUB and its many features varies across reading devices and applications. Use your device or app settings to customize the presentation to your liking. Settings that you can customize often include font, font size, single or double column, landscape or portrait mode, and figures that you can click or tap to enlarge. For additional information about the settings and features on your reading device or app, visit the device manufacturers Web site.
Many titles include programming code or configuration examples. To optimize the presentation of these elements, view the e-book in single-column, landscape mode and adjust the font size to the smallest setting. In addition to presenting code and configurations in the reflowable text format, we have included images of the code that mimic the presentation found in the print book; therefore, where the reflowable format may compromise the presentation of the code listing, you will see a Click here to view code image link. Click the link to view the print-fidelity code image. To return to the previous page viewed, click the Back button on your device or app.
Game Programming in C++
Creating 3D Games
Sanjay Madhav
Boston Columbus Indianapolis New York San Francisco
Amsterdam Cape Town Dubai London Madrid Milan
Munich Paris Montreal Toronto Delhi Mexico City So
Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals.
The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.
For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at or (800) 382-3419.
For government sales inquiries, please contact .
For questions about sales outside the U.S., please contact .
Visit us on the Web: informit.com/aw
Library of Congress Control Number: 2017964125
Copyright 2018 Pearson Education, Inc.
All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, request forms, and the appropriate contacts within the Pearson Education Global Rights & Permissions Department, please visit www.pearsoned.com/permissions/.
Overwatch is a trademark of Blizzard Entertainment, Inc., in the U.S. and/or other countries.
Call of Duty is a registered trademark of Activision Publishing, Inc.
Uncharted and Horizon: Zero Dawn are trademarks of and God of War is a registered trademark of Sony Interactive Entertainment LLC.
Visual Studio, Xbox, and Windows are registered trademarks of Microsoft Corporation.
Apple, iOS, Mac, macOS, and Xcode are registered trademarks of Apple Inc.
GitHub is a registered trademark of GitHub, Inc.
OpenGL and the oval logo are trademarks or registered trademarks of Silicon Graphics, Inc. in the United States and/or other countries worldwide.
Linux is a registered trademark of Linus Torvalds.
FMOD is a registered trademark of Firelight Technologies Pty, Ltd.
Pac-Man is a registered trademark of Bandai Namco Entertainment Inc.
Asteroids and Pong are registered trademarks of Atari Interactive Inc.
PlayStation is a registered trademark of Sony Interactive Entertainment Inc.
Android is a registered trademark of Google Inc.
Unreal is a trademark or registered trademark of Epic Games, Inc. in the United States of America and elsewhere.
Unity is a registered trademark of Unity Technologies.
Maya and FBX are registered trademarks of Autodesk, Inc., in the USA and other countries.
Skyrim is a registered trademark of ZeniMax Media Inc.
Planet Coaster is a registered trademark of Frontier Developments Plc.
ISBN-13: 978-0-13-459720-1
ISBN-10: 0-13-459720-6
1 18
Editor-in-Chief
Mark Taub
Executive Editor
Laura Lewin
Development Editor
Michael Thurston
Managing Editor
Sandra Schroeder
Tech Editors
Josh Glazer
Brian Overland
Matt Whiting
Senior Project Editor
Lori Lyons
Production Manager
Dhayanidhi Karunanidhi
Copy Editor
Kitty Wilson
Indexer
Lisa Stumpf
Proofreader
Larry Sulky
Editorial Assistant
Courtney Martin
Cover Designer
Chuti Prasertsith
Compositor
codemantra
To my family and friends: Thanks for the support .
Contents at a Glance
Register your copy of Game Programming in C++ on the InformIT site for convenient access to updates and corrections as they become available. To start the registration process, go to informit.com/register and log in or create an account. Enter the product ISBN 9780134597201 and click Submit. Look on the Registered Products tab for an Access Bonus Content link next to this product, and follow that link to access any available bonus materials. If you would like to be notified of exclusive offers on new editions and updates, please check the box to receive email from us.
Contents
Preface
Today, video games are some of the most popular forms of entertainment. Newzoos Global Games Market Report estimates over $100 billion in revenue for games in 2017. This staggering amount shows how popular this field truly is. Because of the size of this market, game programmers are in low supply and high demand.
Alongside this explosion of games, game technology has become increasingly democratized. A single developer can make award-winning and hit games by using one of many popular game engines and tools. For game designers, these tools are fantastic. So what value is there in learning how to program games in C++?
If you take a step back, you can see that many game engines and tools are, at their core, written in C++. This means that C++ is ultimately the technology behind every game created using one of these tools.
Furthermore, top-notch developers who release some of the most popular games todayincluding Overwatch , Call of Duty , and Uncharted still predominantly use C++ because it provides a great combination of performance and usability. Thus, any developer who wants to eventually work for one of these companies needs a strong understanding of programming gamesspecifically in C++.
This book dives into many of the technologies and systems that real game developers use. The basis for much of the material in this book is video game programming courses taught at the University of Southern California over the course of almost a decade. The approach used in this book has successfully prepared many students to make it in the video games industry.