\chapter{Preface}

\longpage
A few years ago I was browsing the computer section at a local bookstore when I bumped into another computer enthusiast. He introduced himself as a game programmer, mentioned a few of the projects he had worked on, and told me about his latest fascination: Linux. It meant little to me at the time, but I filed the conversation away for future reference, and eventually I remembered the name and installed Linux on my home computer.

The first few months were not easy. Linux is vastly different from DOS or Windows, and it took some getting used to. But persistence paid off, and soon I felt confident enough with Linux to make the permanent switch. The development tools rocked, and I was impressed by the fact that code mistakes almost never led to system crashes. Once I realized what I'd been missing, I never wanted to go back to Windows again.

Except to play games. A group of friends from school used to hold networked gaming parties (\firstterm{netfetes}, in the parlance of the crowd), and all of the games they played relied on Windows and DOS. I reluctantly kept a minimal copy of Windows on one of my drives so I wouldn't be left out of netfeting.

Linux is a great operating system for developers, and even for casual users who don't mind the initial learning curve. But until recently, Linux has been lousy for gaming. This isn't due to any technical shortcoming; Linux has plenty of performance and stability to support high-performance multimedia applications. It did, however, lack support from game developers. Thanks to portable game programming toolkits like SDL and OpenAL, this is beginning to change. Linux still hasn't seen very much original game development, but Linux users now have access to \firstterm{ported} (converted) versions of a number of major commercial games, produced mainly by Loki Software, Inc.

Game programming has been one of my hobbies ever since my first Commodore 64 computer, and I wasn't about to leave it behind when I left the Windows world for Linux. The SVGALib library held me over for a while, but SDL quickly took over as my favorite way to write Linux games. After meeting the Loki crew at a Linux trade show, I decided that Linux gaming meant business, and got the idea to write a book about it. A year later, it is finally finished, and I hope you enjoy reading it.

\section{Who This Book Is For}

This book is for anyone who wants to learn how to write games for Linux. I assume that you know the basics of working with Linux; if you know enough to start X, open a terminal, copy files around, and fire up a text editor, you're good to go. I also assume that you have a reasonable grasp of the C programming language. Flip through the book and see if you can decipher the syntax of the examples. We'll go through all of the necessary library calls, so don't worry if you see a bunch of unfamiliar function names, but you should be able to understand the majority of the actual code. No prior experience with multimedia programming is assumed, so don't worry if you've never had the perverse pleasure of hacking a graphics register or shoving a pixel into memory. All in good time!

Although this isn't a reference manual in the traditional sense, chapters \ref{ch:masteringsdl}, \ref{ch:linuxaudio}, \ref{ch:gamescripting}, and \ref{ch:linuxconsole} provide reference boxes for most of the API functions we cover. I hope that even experienced multimedia programmers can find something useful here.

I will not discuss 3D programming in this book. There are already plenty of excellent books on OpenGL, and only a small bit of OpenGL programming is directly related to Linux. However, I will demonstrate how to use SDL as an effective replacement for the GLUT toolkit; see page \pageref{sect:sdlopengl}.

\section{Online Resources}

I made the decision to not include a CD-ROM with this book. This choice was both personal and pragmatic. Books CDs tend to get lost or damaged, no matter how hard one tries to keep them in a safe place. CD inserts are usually impossible to open without damaging the book in some way. And finally, the data that would be contained on the CD (presumably the libraries and examples we'll talk about in this book) would be obsolete by the time the book hit the press.

Instead, we've put together a Web site with all the book's examples and links to various libraries you'll need. You can access this site from either \ulink{http://www.nostarch.com} or \ulink{http://www.lokigames.com}. Feel free to share the example code with your friends and colleagues, and use it in your projects; license details are included in the code archive.

\section{Acknowledgements}

This book would not have been possible without help from a lot of people. No~Starch~Press was a pleasure to work with, even when I switched from SGML to \LaTeX\ in the middle of the project and mentioned that I would need printouts instead of Word documents for copyedit. I thank everyone at No~Starch---especially Karol Jurado and Bill Pollock---for their patience and willingness to accomodate a first-time author. Thanks also to Amanda Staab for making \booktitle{Programming Linux Games} known to the world.

I'd like to thank the Loki crew for keeping my life interesting during the summer of 2000; especially Sam~Lantinga for tolerating my never-ending SDL and framebuffer console questions, Joe~Valenzuela for helping me get up to speed on OpenAL, and Lance~Colvin for providing me with a place to stay during the summer. Scott~Draeker was always there to answer questions and provide feedback, even in the midst of slipping deadlines an an ever-changing table of contents. This book would not have happened without his ongoing support.

The following people deserve a virtual beer for helping me in various ways. The list is long, but so was the process of writing this book. Here goes: Martin~Donlon for starting the SDL Documentation Project and providing me with helpful hints as I wrote Chapter \ref{ch:masteringsdl}, Ray~Kelm for for commenting on Win32 portability issues, Matt~Friedly of \ulink{http://phluid.acid.org} for allowing me to use some of his tracker music (\filename{reflux.ogg}) in \gametitle{Penguin Warrior}, my Georgia Tech roommates Daniel~Larsen, Matt~Might, Anthony~Chen, and Frank~Cheng for tolerating my odd hacking hours and fits of frustration over badly-documented APIs, Mike~Phillips for obtaining excellent screenshots (which unfortunately I could not use due to the virtual impossibility of dealing with game company legal departments), my IBM Model M keyboard for not breaking regardless of the velocity of my fist, Andy~Mecham of Loki for pyrotechnic entertainment, Nicholas~Vining for helping me test code and getting me involved with the Kosmos Online project, Steve~Shack for pointing out inaccuracies, Mathew~Lang for scouring Chapter 1 with an avid gamer's eye, Lee~Nau for pointing out errors, David~Megginson and Andreas~Umbach for screenshots, Damon~Ragno, Michele~Bini, and Mitch~Allmond for helping me test the networking code, Terry~Hendrix for telling me I was insane, Andrew Beardmore for providing helpful feedback on an early draft, Erik~de~Castro~Lopo for libsndfile, Jason~Wong, Andrew~Buckner, and the rest of the netfeters for screenshots and comments, David~Hedbor, Steven~Fuller, Dan~Olson, Mike~Delaney, Anoakie~Turner, and a bot named Nerf for making IRC interesting, Brian~Crowder, Ryan~Gordon, Michael~Vance, Andrew~Henderson the assembly guru, Daniel~Vogel, Bernd~Kreimeier, Rafael Barrero for keeping all the systems running, Terry~Warner, David~Ranger, Kris~Doyle, Brad~Harris, Steven~Reinemund, Patrick~Buchanan (definitely not to be confused with the presidential candidate by the same name), Kyle~Johnson, Josh~Litherland, Ola~Nordstr\"{o}m, Amir~Ebrahimi, Sonny~Rao, David~Shea, Moshe~Jacobson, Lincoln~Durey, St\'{e}phane~Peter, Mike~Imamura, Pedro~Pla, and anyone else whom I may have left out. Writing a book is a long and fairly dull process. You made it a lot easier.

I'd also like to thank all of my professors from years past. I can't hope to name them all here (nor are you likely interested in viewing such a catalog), but in particular I would like to acknowledge Dr.\ Richard Newcomb, for being a truly remarkable high school calculus teacher as well as getting me started with \TeX, Greg~Novinski for guiding me away from trouble for eight years at Cistercian, Fr.\ ~Gregory~Schweers, Jackie~Greenfield, Gary~Nied, and Dr.\ ~Tom~Pruit for teaching me how to write, Fr.~Mark~Ripperger for feeding my programming and electronics addiction, and Fr.~Denis~Farkasfalvy for a certain incident a few years ago that I'm sure he recalls.

And of course my parents. I simply could not have written this book without their encouragement and support.

\vspace{0.2in}
\begin{changemargin}{3.5in}{0in}
John Hall \\
Atlanta, GA
\end{changemargin}
