Day: July 27, 2006

Getting Started in Game Programming

I’ve thought for a long time about writing an article on how to become a game programmer on your own. The problem is that everybody and their kid sister has written an article on this subject, and most of them are better than anything I could write.

But there is one thing I can do to help the budding game developer, and that’s point out which books he probably should be reading (and which ones he probably should avoid).

There are a couple steps on the path to becoming a game programmer. First, you have to pick your language. Your language is C++. There, wasn’t that easy?

Yeah, I’m being a little facetious. If you’re just writing games for yourself and don’t want to get an industry job or ever work on a team, you can write your games using whatever language, libraries and helper programs you want.

But if you want to become a professional, you’re going to have to learn C++. End of story. Oh sure, other languages might be helpful, but the vast majority of game development (both on PCs and on consoles) is done in C++. Why? Because it works, and more libraries have been written for it than any other language. There are free C++ compilers for almost every operating system on the planet. And there are more books on C++ than any other programming language.

Let’s talk about what to avoid. Avoid books that promise to teach you how to program a game in a short amount of time. What most of these books teach is how to use a scripting language or a gamemaker program to make games. This won’t be useful to you if you want to become a professional game developer. Specifically avoid the book 3D Game Programming All in One, as this book is basically just a tutorial for the Torque game engine and teaches you nothing about programming. Also take careful note of any book that promises to teach you DirectX; some of them actually use Visual Basic instead of C++, which makes them darn near useless.

So here’s what I suggest.

First, get a compiler. You cannot learn C++ without a compiler. If you’re on Windows, get Visual C++ Express and be done with it; there’s no sense in messing around with anything else. If you’re on another operating system you’ll probably end up with some version of GCC, which I don’t know much about, but it’s in widespread use so research shouldn’t be that hard.

Second, you need to learn basic C++ syntax. There are a lot of books on this subject. Tons and tons of them. Most of them are crap, but even a crappy book can suffice here if it does actually cover the basics. Now, back when I learned C++ I did it from a book that included a floppy disk with a copy of Borland’s Turbo C++ on it…that’s how long ago it was. So I’m not that familiar with the current crop of books, but the one I keep hearing about is Accelerated C++. You probably won’t go wrong with it (but this is the only book I will recommend that I haven’t actually read).

Once you’ve learned basic C++ and are familiar with your compiler, it’s time to get a more thorough overview of the language, and the best book for that is none other than Stroustrup’s The C++ Programming Language. Now, this book covers the entire language and most of the Standard Template Library and it’s not particularly difficult to read. But it should not be your first C++ book, because it isn’t a tutorial. I would recommend going straight through the book, reading each section and writing little programs in your compiler to demonstrate to yourself that you understand each concept – this is exactly how I learned C++ on my own. I would also recommend making double sure that you understand how classes work, how inheritance works, and how pointers work before you proceed to the next level. If you can’t tell me what a reference to a pointer is and why you would want to use one, you probably shouldn’t go on yet.

Now you know how to do pretty much everything in C++. But there’s more to learn, because there are a lot of things in C++ that you shouldn’t do even though you can. The next two books I would recommend are Meyers’ Effective C++ and McConnell’s Code Complete. Both of these are outstanding books that will make you a much better programmer practically overnight if you take the time to read and understand everything they say. Effective C++ will tell you about all the common traps C++ programmers fall into and explain how to avoid them. Code Complete is a bit higher level – it will teach you how to design your programs before you start coding so that your code doesn’t get so tangled you can’t deal with it any more. Code Complete is especially important if you plan to become part of a programming team.

Now, during the course of reading Effective C++ and Code Complete, you will probably encounter information that contradicts what you read in earlier books. In this case, these two books win.

Now you’re a hardcore C++ developer, but you still don’t know anything about game development. Therefore, your next book should be Llopis’ C++ For Game Programmers. This book is going to directly contradict things you’ve previously read; in this case, this book wins. You’ll be doing lots of stuff in game development that would make your average OOPmeister wince; that’s just the way game development is. Some of the content in the book will be stuff you already know. That’s okay, because the rest of it is pure gold. Pay special attention to the section on memory management; this is a vital concept that most game development books ignore because it can be quite difficult.

I’m also going to recommend that you read McShaffry’s Game Coding Complete at this point. Make sure you get the latest edition, which at the time of this writing is the fourth edition. This is the only book I’ve ever seen to cover how to design and write an overall game engine, as well as how to create a resource handling system. Again, these are both topics that most game development books ignore because of their difficulty. This book will also cover the basics of just about every aspect of game development, including graphics, sound, physics and networking.

If you’ve been reading and coding dilligently then you should now have a solid understanding of the basics of professional-level game development. Now there isn’t so much a progression as just a list of books I’d recommend.

The Graphics Gems series – if you’re doing 3D programming, and especially if you’re doing 3D programming on a platform that does not have hardware acceleration, then you must have at least the first book in this series. Yes, it is terribly expensive, but it’s worth it.

The Game Programming Gems series – this was an attempt to create a series like Graphics Gems, but for general game development. As they progressed the information presented became more specialized and less vital – but again, you should definitely own at least the first book.

If you are just starting out with Direct3D, then the book I’d recommend is Introduction to 3D Game Programming with DirectX 9.0 by Frank Luna. This book actually lives up to its name and will take you in baby steps from initializing Direct3D to particle systems, multitexturing, shadows, landscape rendering, picking, and pixel and vertex shaders. Make sure you get the first edition of this book, as the second edition will focus on DirectX 10 and will do everything with shaders. That’ll be interesting, but it won’t be a “for beginners” book like the first edition is.

Hope this helps!


Somewhat Structured

I really should check my incoming links more often. Casey Dunham from Somewhat Structured Thoughts wrote a post about my combat prototype and apparently didn’t hate it. Thanks, Casey! Hopefully I’ll finish it one day!