0% found this document useful (0 votes)
18 views

Programming Linux Games 1st Edition Loki Software - Download the ebook now for the best reading experience

The document provides a list of various programming ebooks available for instant download at ebookgate.com, including titles on Linux system programming, game development, and software engineering. Each title is linked for easy access, and the document emphasizes the availability of different ebook formats. Additionally, it includes copyright information and details about the distribution of the book 'Programming Linux Games' by Loki Software, Inc.

Uploaded by

kueviobhaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Programming Linux Games 1st Edition Loki Software - Download the ebook now for the best reading experience

The document provides a list of various programming ebooks available for instant download at ebookgate.com, including titles on Linux system programming, game development, and software engineering. Each title is linked for easy access, and the document emphasizes the availability of different ebook formats. Additionally, it includes copyright information and details about the distribution of the book 'Programming Linux Games' by Loki Software, Inc.

Uploaded by

kueviobhaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 81

Instant Ebook Access, One Click Away – Begin at ebookgate.

com

Programming Linux Games 1st Edition Loki Software

https://ebookgate.com/product/programming-linux-games-1st-
edition-loki-software/

OR CLICK BUTTON

DOWLOAD EBOOK

Get Instant Ebook Downloads – Browse at https://ebookgate.com


Click here to visit ebookgate.com and download ebook now
Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Linux system programming 1st Edition Robert Love

https://ebookgate.com/product/linux-system-programming-1st-edition-
robert-love/

ebookgate.com

Go Systems Programming Master Linux and Unix system level


programming with Go 1st Edition Mihalis Tsoukalos

https://ebookgate.com/product/go-systems-programming-master-linux-and-
unix-system-level-programming-with-go-1st-edition-mihalis-tsoukalos/

ebookgate.com

GNU Linux application programming 1st Edition M. Tim(M.


Tim Jones) Jones

https://ebookgate.com/product/gnu-linux-application-programming-1st-
edition-m-timm-tim-jones-jones/

ebookgate.com

Erlang Programming a Concurrent Approach to Software


Development 1st Edition Francesco Cesarini

https://ebookgate.com/product/erlang-programming-a-concurrent-
approach-to-software-development-1st-edition-francesco-cesarini/

ebookgate.com
Programming Erlang Software for a Concurrent World Second
Edition Joe Armstrong

https://ebookgate.com/product/programming-erlang-software-for-a-
concurrent-world-second-edition-joe-armstrong/

ebookgate.com

Software Engineering For Students A Programming Approach


4th Edition Douglas Bell

https://ebookgate.com/product/software-engineering-for-students-a-
programming-approach-4th-edition-douglas-bell/

ebookgate.com

Assembly Language Step by Step Programming with Linux 3rd


Edition Edition Jeff Duntemann

https://ebookgate.com/product/assembly-language-step-by-step-
programming-with-linux-3rd-edition-edition-jeff-duntemann/

ebookgate.com

The Art of R Programming A Tour of Statistical Software


Design 1st Edition Norman Matloff

https://ebookgate.com/product/the-art-of-r-programming-a-tour-of-
statistical-software-design-1st-edition-norman-matloff/

ebookgate.com

Web Application Design and Implementation Apache 2 PHP5


MySQL JavaScript and Linux UNIX Quantitative Software
Engineering Series 1st Edition Steven A. Gabarró
https://ebookgate.com/product/web-application-design-and-
implementation-apache-2-php5-mysql-javascript-and-linux-unix-
quantitative-software-engineering-series-1st-edition-steven-a-gabarro/
ebookgate.com
Programming Linux Games
Programming Linux Games

Loki Software, Inc.


with John R. Hall

An imprint of No Starch Press, Inc.


San Francisco
Programming Linux Games. Copyright c 2001 by Loki Software, Inc.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any
means, electronic or mechanical, including photocopying, recording, or by any information storage or
retrieval system, without the prior written permission of the copyright owner and the publisher.

Printed in the United States of America


1 2 3 4 5 6 7 8 9 10—04 03 02 01

Trademarked names are used throughout this book. Rather than including a funny little trademark
symbol with every occurrence of a trademarked name, we are using the names only in an editorial
fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.

Co-publishers: William Pollock and Phil Hughes


Project Editor: Karol Jurado
Assistant Editor: Nick Hoff
Cover and Interior Design: Octopod Studios
Copyeditor: Rebecca Pepper
Proofreader: Ken DellaPenta

Distributed to the book trade in the United States by Publishers Group West, 1700 Fourth Street,
Berkeley, California 94710, phone: 800–788–3123 or 510–528–1444, fax: 510–528–3444

Distributed to the book trade in Canada by Jacqueline Gross & Associates, Inc., One Atlantic Avenue,
Suite 105, Toronto, Ontario M6K E7 Canada, phone: 416–531-06737, fax: 416–531–4259

For information on translations or book distributors outside the United States, please contact
No Starch Press, Inc. directly:

No Starch Press, Inc.


555 De Haro Street, Suite 250
San Francisco, CA 94107
phone: 415–863–9900; fax: 415–863–9950;
[email protected]; http://www.nostarch.com

The information in this book is distributed on an “As Is” basis, without warranty. While every
precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc.
shall have any liability to any person or entity with respect to any loss or damage caused or alleged to
be caused directly or indirectly by the information contained in it.

Library of Congress Cataloging-in-Publication Data

Programming linux games / Loki Software, Inc.


p. cm.
Includes index.
ISBN 1-886411-48-4 (pbk.)
1. Computer games--programming. 2. Linux. I. Loki Software, Inc.

QA76.76.C672 .L56 2001 00-052689


794.8’15268--dc21
Contents

Foreword i

Preface iii
Who This Book Is For . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv
Online Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv
Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v

1 The Anatomy of a Game 1


A Quick Survey of Game Genres . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Simulation Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
First-Person Shooters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Real-time Strategy Games . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Turn-Based Strategy Games . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Role-Playing Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Puzzle Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Multiuser Dungeons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
A Quick Look Under the Hood . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
The Input Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
The Display Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2 CONTENTS

The Audio Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13


The Network Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
The Update Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
The Game Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

2 Linux Development Tools 17


Programming Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
vi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Emacs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
NEdit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Compiling Programs Under Linux . . . . . . . . . . . . . . . . . . . . . . . . . 20
Using the Make Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Creating Makefiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Working with Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Static Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Shared Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Linux Linker Quirks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Debugging Linux Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Compiling for Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
ddd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Bug Tracking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Project Management with CVS . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
A Brief Tutorial on CVS . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Other Useful Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Rapid Text Searching with grep . . . . . . . . . . . . . . . . . . . . . . . . 49
CONTENTS 3

Updating Source with diff and patch . . . . . . . . . . . . . . . . . . . . . 50

3 Linux Gaming APIs 53


Graphics APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
SVGALib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
GGI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
SDL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
ClanLib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
OpenGL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Plib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Glide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Xlib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Graphical User Interface Toolkits . . . . . . . . . . . . . . . . . . . . . . . . . . 59
GTK+ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Tk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Fltk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Qt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
SDL GUI Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Audio APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
OSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
ALSA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
ESD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
OpenAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Scripting Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Tcl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Guile and MzScheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Python and Perl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
4 CONTENTS

Networking APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
BSD Sockets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
OpenPlay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
IPX and SPX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
File Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
libpng and libjpeg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
libaudiofile and libsndfile . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Ogg Vorbis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
The SDL MPEG Library, SMPEG . . . . . . . . . . . . . . . . . . . . . . 68
zlib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

4 Mastering SDL 69
Computer Graphics Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
The Framebuffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
The SDL Video API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Setting Up the Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Direct Surface Drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Drawing with Blits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Colorkeys and Transparency . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Loading Other Image Formats . . . . . . . . . . . . . . . . . . . . . . . . . 92
Alpha Blending . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Achieving Smooth Animation with SDL . . . . . . . . . . . . . . . . . . . 97
Input and Event Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Processing Mouse Events . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Processing Keyboard Events . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Processing Joystick Events . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Multithreading with SDL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
CONTENTS 5

SDL Audio Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125


Representing Sound with PCM . . . . . . . . . . . . . . . . . . . . . . . . 125
Feeding a Sound Card . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
An Example of SDL Audio Playback . . . . . . . . . . . . . . . . . . . . . 129
Integrating OpenGL with SDL . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Penguin Warrior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Creating Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Implementing a Parallaxing Scroller in SDL . . . . . . . . . . . . . . . . . 147
A Simple Particle System . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Game Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158

5 Linux Audio Programming 161


Competing APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Introducing Multi-Play . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Loading Sound Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Using libsndfile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Other Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Using OSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Reality Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Achieving Higher Performance with Direct DMA Buffer Access . . . . . . 178
Playing Sound with ALSA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Sharing the Sound Card with ESD . . . . . . . . . . . . . . . . . . . . . . . . . 195
Building Multi-Play . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Environmental Audio with OpenAL . . . . . . . . . . . . . . . . . . . . . . . . 206
OpenAL Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Adding Environmental Audio to Penguin Warrior . . . . . . . . . . . . . . 213
Implementing Game Music with Ogg Vorbis . . . . . . . . . . . . . . . . . . . . 222
6 CONTENTS

Working with Vorbis Files . . . . . . . . . . . . . . . . . . . . . . . . . . . 223


Adding Music to Penguin Warrior . . . . . . . . . . . . . . . . . . . . . . 227

6 Game Scripting Under Linux 237


A Crash Course in Tcl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
Built-in Tcl Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Interfacing Tcl with C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Linking Against Tcl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
Executing Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
Understanding Commands and Objects . . . . . . . . . . . . . . . . . . . 250
A Simple Scripting Engine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Designing a Game Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
Applying Scripting to the Real World . . . . . . . . . . . . . . . . . . . . . . . 265
Single Versus Multiple Contexts . . . . . . . . . . . . . . . . . . . . . . . . 266
Can We Trust the Script? . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
Script Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
Who’s Writing the Script? . . . . . . . . . . . . . . . . . . . . . . . . . . . 268

7 Networked Gaming with Linux 271


’Tis a Big Net, Quoth the Raven . . . . . . . . . . . . . . . . . . . . . . . . . . 272
Internet Protocols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
Addresses and Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
Name Resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Socket Programming 101 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Sockets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Connecting TCP Sockets . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
Receiving TCP Connections . . . . . . . . . . . . . . . . . . . . . . . . . . 285
CONTENTS 7

Working with UDP Sockets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292


Multiplayer Penguin Warrior . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Network Gaming Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
Penguin Warrior’s Networking System . . . . . . . . . . . . . . . . . . . . 302
Network Game Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
Security Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312

8 Gaming with the Linux Console 315


Pros and Cons of the Linux Framebuffer . . . . . . . . . . . . . . . . . . . . . . 316
Setting Up a Framebuffer Device . . . . . . . . . . . . . . . . . . . . . . . . . . 318
A First Foray into Framebuffer Programming . . . . . . . . . . . . . . . . . . . 318
Setting Framebuffer Video Modes . . . . . . . . . . . . . . . . . . . . . . . . . . 326
How Video Scanning Works . . . . . . . . . . . . . . . . . . . . . . . . . . 327
The Mode Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
An Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
Use the Source, Luke! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
Console Input Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
Keyboard Input from a Terminal . . . . . . . . . . . . . . . . . . . . . . . 338
Mouse Input with GPM . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348

9 Finishing Penguin Warrior 355


Adding Weapons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
Drawing Phasers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
Detecting Phaser Hits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
Imposing a Sane Rate of Fire . . . . . . . . . . . . . . . . . . . . . . . . . 364
Creating Status Displays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
In Retrospect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
8 CONTENTS

10 To Every Man a Linux Distribution 379


Source or Binary? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
Local Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
Linux Isn’t Alone: Supporting FreeBSD . . . . . . . . . . . . . . . . . . . . . . 383
Packaging Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
Graphical Installation Goodness: Loki’s Setup Program . . . . . . . . . . . . . 387
Understanding the Linux Filesystem Standard . . . . . . . . . . . . . . . . . . 393

Glossary of Terms 399

Bibliography 405
Foreword

I was honored when John asked me to write the foreword for this book. I’ve
spent the last few years in an opportunity that few have had, the opportunity to
get up close and personal with the source code to quite a few of the world’s most
popular (and some less popular) games. I’ve had the chance to port these games
to the Linux operating system, something that has been a source of sweat and
sometimes swearing, but always of pride and joy.
In these pages you will find the jewels of wisdom that John has picked up over a
year of picking our brains, experimenting, and experience. Much of the
information contained here has never been documented all in one place, so
whether you’re a beginner looking to start an open source game or a seasoned
professional, I think you’ll find something to interest you. John has done a great
job presenting the tools available for developing your games on Linux.
Enjoy!

Sam Lantinga
Author of SDL
Preface

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 (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 ported (converted) versions of a number of major commercial games,
produced mainly by Loki Software, Inc.
iv PREFACE

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.

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 4, 5, 6,
and 8 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 140.

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
PREFACE v

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
http://www.nostarch.com or 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.

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 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 4, Ray Kelm for for commenting on Win32
portability issues, Matt Friedly of http://phluid.acid.org for allowing me to
use some of his tracker music (reflux.ogg) in 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
vi PREFACE

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 (apologies for forgetting your real
name; everyone online knows you as the ubiquitous “Mongoose”),
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,
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öm,
Amir Ebrahimi, Sonny Rao, David Shea, Moshe Jacobson, Lincoln Durey,
Sté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.

John Hall
Atlanta, GA
Chapter 1

The Anatomy of a Game

In 1991 a Finnish university student named Linus Torvalds began working on a


new operating system in his spare time. He didn’t work in isolation, nor did he
make a big deal about what he was doing; rather, he modestly invited
programmers from all over the world to join his project, which he dubbed
“Linux.” This loosely knit team of students, professionals, and hobbyists
collaborated through the Internet, with the expectation of learning a bit about
programming and having a good time. Linus never thought that his project
would spawn an entire industry.
Since then, Linux has grown into a general-purpose operating system for a wide
variety of hardware platforms. With more than 10 million users (a number that
is constantly growing), the Linux platform offers a sizable audience for computer
games. It is now capable of accelerated 3D graphics, environmental audio, and
seamless game controller handling, in addition to the server tasks that UNIX-like
operating systems generally carry out. Although Linux is still evolving, it is
already a solid environment for serious game development.
This book describes the toolkits and the environments that allow programmers
to write 2D and 3D games for Linux. We will learn how to draw animated
graphics on the screen, how to play high-quality digital sound through several
different software libraries, and how to set up OpenGL to create fluid 3D
graphics. By the end of this book, you will know what makes Linux games tick,
and how to create your own games for this platform.
2 CHAPTER 1

This book is not about game design, the mathematics of 3D graphics, or


advanced OpenGL programming. These topics are best left to books of their
own; I could not hope to do them justice here. However, with the knowledge you
will gain from this book, you will be prepared to tackle these topics later on.
Before we begin our discussion of Linux game programming, let’s take a quick
glance at our surroundings in the gaming industry so that you can better
understand what goes into this type of project.

A Quick Survey of Game Genres


Computer games tend to fall into any one of a number of distinct genres. Many
players have strong preferences for certain genres, which makes this an
important issue for game designers to consider. And, the presentation of a game
concept can make an enormous difference in its success.

Simulation Games

The simulation genre encompasses a wide variety of games, from flight


simulators to Mech combat scenarios. An ideal simulator provides a high level of
realism in graphics, sound, and game physics. Some popular simulation games
are Heavy Gear II, MechWarrior, and Microsoft Flight Simulator. The basic goal
of any simulation game is to put the player behind the controls of something
exciting, something that he or she probably would not have access to in real life.
Simulations strive for immersion.
Simulation games (sims) are basically at two extremes. Some simulations aim for
absolute realism, seeking to entertain the player with an almost completely
accurate portrayal of real life. These “games” are sometimes even used for
real-life training purposes. Other sims, like the Heavy Gear and MechWarrior
series, trade realism for pure entertainment value. These games are based only
loosely on reality; they simulate imaginary vehicles with extraordinary but
rather impossible capabilities. (Interestingly, the MechWarrior and Heavy Gear
computer games are based on pencil-and-paper role-playing games.)
Simulations pose a serious development challenge. Since a good modern
simulation requires high-quality 3D graphics, detailed vehicle models, a game
THE ANATOMY OF A GAME 3

physics system for simulating the physics of the real world, realistic input
response, network capabilities, and possibly a certain amount of artificial
intelligence for the computer-controlled players, a contemporay sim is not trivial
to construct.
What makes a simulation game successful? Let’s look at a couple of examples: a
“realistic” simulator and an “action” simulator. Microsoft Flight Simulator is a
popular flight simulator for the PC (and is in fact the current iteration of a long
line of flight simulators by the same developers, dating back to the Commodore
64) that combines realistic control with excellent 3D graphics and interesting
airplanes, and the terrain looks reasonably close to the real world’s.1 An
experienced pilot could certainly tell the difference between Microsoft Flight
Simulator and a real airplane, but it’s nonetheless an enjoyable simulation.
Microsoft Flight Simulator tries to make the players feel like they were in the
cockpit, not just collecting cellulite behind the keyboard of a fast computer.
Although this game will not run under Linux (except possibly under WINE2 ),
it’s certainly worth a look if you’re thinking of writing a flight simulator.
On another front, the Flight Gear project is presently developing a free flight
simulator for Linux. The simulator already sports a realistic physics model and
an excellent terrain engine, and it is slated to eventually become one of the best
flight simulators ever. Flight Gear is portable to many platforms, as it is based
almost entirely on open technology.
Heavy Gear II from Activision is a good example of an action simulator. It puts
the player behind the controls of a multiton Gear (a two-legged walking vehicle
with big guns) and succeeds because of its realistic graphics, simple but capable
control system, damage simulation, and interesting gameplay. The player is in
complete control of his or her Gear and is free to do anything during the game

1
One of the first rules of game design (and, to some extent, of computer graphics in general)
is that it doesn’t matter if something is realistic as long as it looks realistic. Unfortunately,
most people don’t have 5-terahertz machines, so game creators have to take a few shortcuts.
Most flight simulators really aren’t that realistic when it comes down to it, but they sure
seem realistic.
2
http://www.winehq.com.
4 CHAPTER 1

Screen shot from Flight Gear


Image courtesy of David Megginson

(although accomplishing the mission without getting killed is usually the best
plan). Heavy Gear II creates a sense of power and euphoria in the player, and
this makes it a pleasant experience. Activision has also published several
MechWarrior titles that are very similar to the Heavy Gear series.
Finally, one of my personal favorite simulation games (from many years ago) is
Corncob 3D, a completely unrealistic shareware, DOS-based flight simulator.
Guised as a flight simulator, this is a classic “Defend Earth from Space Invasion”
game with lots of missions, missiles, and mayhem. By today’s standards, of
course, this game is laughable. But it ran well on the low-end hardware of the
day, and it was a lot of fun to play. Corncob 3D is a good example of a simulator
that trades realism for entertainment value.

First-Person Shooters

First-person shooters are some of the most popular games today. They typically
involve a weak story line (with exceptions, of course), hordes of enemies, big
explosions, and lots of blood. The basic premise of most first-person shooters is
to give the player an adrenaline rush by putting him in the middle of a hostile
THE ANATOMY OF A GAME 5

Screen shot from GLTron, based on an 80’s sci-fi movie


Image courtesy of Andreas Umbach

environment with insidious monsters and powerful weapons. These games have
improved in quality over the years and are beginning to reach a very high level of
realism. Some popular ones are Quake 3, Half-Life, and Soldier of Fortune, all of
which are available for Linux (although Half-Life is not native to Linux, and
requires the WINE library to run).
High-quality first-person shooters are difficult to produce, not just because
they’re hard to program (facilitated by standard 3D libraries such as OpenGL),
but also because they require detailed 3D character models and levels. 3D
game-engine programming requires a solid knowledge of linear algebra and a firm
grasp of certain types of data structures. However, mathematically inclined
people are likely to find 3D game programming both challenging and rewarding.
6 CHAPTER 1

Valve’s Half-Life is one of the most successful first-person shooters, combining


the thrill of a typical FPS with a compelling storyline, amazingly realistic
enemies, and an excellent multiplayer mode. Half-Life is based on Quake II’s
rendering technology, but that is where the similarities end. Unlike the Quake
series, Half-Life has a plot, an excellent single-player mode as well as network
game support, and a more complex virtual environment (complete with
moveable objects and vehicles).
Another interesting first-person shooter (also based on the Quake II engine) is
Activision’s Soldier of Fortune. Decried by critics as gratuitously violent (and
hence “indexed” in Germany and classified as an adult title elsewhere), Soldier
of Fortune combines traditional first-person shooter action with frightening
realism, even going so far as to correctly simulate bodily damage due to gunshot
wounds. It also has a solid plot that develops throughout the game. Overall, a
very enjoyable title, if you’re not disturbed by the violence. (I won’t go into the
highly emotional politics surrounding this subject.)
A current trend is to mix first-person 3D technology with the role-playing game.
Deus Ex is one such example, a role-playing game based on the Unreal engine.
Deus Ex has been ported to Linux, and I strongly recommend giving it a try.

Real-time Strategy Games

The genre of games known as Real-Time Strategy (RTS ) games includes such
popular titles as StarCraft, Command and Conquer, and Total
Annihilation—games that allow the player to command individual parts of an
army from an overhead view, with success in battle usually leading to better
equipment and soldiers. Because success is usually determined by a player’s
tactics, these are considered strategy games. RTS games often have a high replay
value; they’re fun to play again and again.
RTS games are comparatively easy to program, because, with some exceptions,
they do not involve 3D graphics or complicated mathematics; however, good RTS
games are hard to produce, and they tend to be few and far between. They often
involve a certain amount of artificial intelligence (AI) programming for
controlling the simulated opponents in single-player games—a fascinating field,
but one that we’ll leave to other sources.
THE ANATOMY OF A GAME 7

StarCraft is by far the most successful RTS game, combining pleasing graphics, a
large selection of well-balanced units, and interesting battlefields in a very
well-rounded game and exciting game. Solid game design is by far the most
important issue in creating a real-time strategy game, and StarCraft is an
excellent example. This is not the first notable game from Blizzard
Entertainment, and it will be interesting to see what Blizzard comes up with in
the future.

Turn-Based Strategy Games

Turn-Based Strategy (TBS ) games are like real-time strategy games, but the
gameplay is divided into turns, usually with no time limit, thus giving the player
time to think and relax, and lending the game an entirely different feel from the
faster-paced strategy games. TBS games are not decided by reflexes, but rather
by careful planning, which often makes them more difficult, and more attractive
to many players. Sid Meier’s Civilization II is widely regarded as the best
turn-based strategy game, because of its balance and replay value.

Deceptively Complex
I once thought that TBS games were easy to write, but then I saw the
source code to Sid Meier’s Alpha Centauri (SMAC). Most players don’t
realize it, but SMAC actually uses a 3D technique called voxels to
render its units on the fly and to draw a height-sensitive landscape with
perspective texture mapping and dynamic palette mapping (made
possible by self-modifying assembly code). Sid Meier’s Alpha Centauri
was obviously not easy to port to Linux. While it’s possible to write a
good TBS game without such sophistication, don’t think of the TBS
genre as an easy way out—its complexity can be deceiving.

Role-Playing Games

Role-Playing Games (RPGs) stem from the Dungeons and Dragons role-playing
system.3 In this type of game, the player assumes the role of one or more

3
There are lots of similar role-playing systems; I just give DND as an example.
8 CHAPTER 1

Screen shot from FreeCiv, a free TBS game


Image courtesy of Paul Zastoupil

characters on some sort of quest. Role-playing games put the player in a world
with many possibilities; a good RPG gives its players a sense of immersion and
true interaction, and allows them to effectively become someone else.
The quality of a role-playing game depends much more on its storyline,
interaction, and depth than on its graphics. Ultima Online is an example of a
good online RPG. While its graphics are not spectacular, the depth of its
gameplay is incredible, because it allows for complex interactions between
players in a virtual universe. Ultima is not exactly a “hard core” RPG, however;
true die-hard RPG gamers often prefer other types of RPGs, such as those
published by Simutronics (http://www.simutronics.com).
THE ANATOMY OF A GAME 9

Screen shot from NetHack, a very strange free RPG project

Puzzle Games

Puzzle games receive less attention than the other game genres, but they deserve
to be mentioned. Puzzle games challenge the player with problems that require
thought and patience. This genre includes everything from simple box-pushing
games (Boxxel and the dangerously addictive Sokoban) to the animated and
ubiquitous Tetris.
A successful puzzle game is usually challenging (but not impossible), pleasant to
look at (graphics should not be ignored), and replayable (one-shot puzzle games
are usually not very enjoyable the second time around, and players don’t
appreciate that). The difficulty involved in creating a puzzle game depends on
the particular game; some are extremely complex, involving massive amounts of
artwork and graphics processing, while others are simple to implement.
10 CHAPTER 1

Screen shot from KSokoban, a version of Sokoban for KDE

Multiuser Dungeons

Multiuser Dungeons (commonly known as MUDs) are massively multiplayer


games, typically hosted on Internet servers and accessed with special MUD client
programs. MUDs are extremely popular because one’s opponents are real people,
not computer-controlled robots. MUDs are essentially text-based role-playing
games, immersing their players in worlds with magical objects, wizardry, and
battle. MUD fans wishing to host a game of their own often obtain a prewritten
MUD server program and develop their own “world” through configuration files
and scripting languages. If they do a good job, they may attract lots of players,
which is very satisfying. Two popular MUD server programs are ROM and
DikuMud, which may be downloaded from the Internet. There are untold
thousands of private ROM-based MUDs on the Internet.
MUDs are relatively easy to create, though writing a MUD server is not trivial,
requiring a solid background in C or similar and a knowledge of network
programming. Creating MUD datafiles requires little programming knowledge
but a lot of creativity. A good MUD has an interesting game world to explore
and a good balance of races and abilities. Also, some MUDs are prone to “god
moding,” or abuse by the person running the server; while this obviously
depends on the players, good design can lessen this undesirable effect.
THE ANATOMY OF A GAME 11

If you’ve never been “mudding,” give it a try. A good MUD can provide a truly
interesting experience. You can find MUDs all over the Internet; just search the
Web for the word “mud.”

A Quick Look Under the Hood


Most games have a lot in common behind the scenes. The engine, or main code,
of a “typical” game (if there is such a thing) can be logically divided into several
subsystems: the input subsystem, the display subsystem, the audio subsystem,
the networking subsystem, the update subsystem, and the main loop. These
subsystems are rarely labelled as such, but you are likely to find all of these
components in any given game engine. Each subsystem is most often
implemented with several separate source files; two or three in small games, but
easily a hundred or more in a large production. We’ll look briefly at each of
these subsystems now, and throughout the rest of the book we will explore
possible ways to implement each.

This Code Is Awful!


If you ever get a peek at the code behind a major commercial game,
please do not take it as a treatise on proper software design or coding!
Games often start out as well-designed software, and they sometimes
even make it to the shelves in a tolerable state of internal organization,
but more often than not a game’s code falls into disarray during the last
few months of development.
Why, you might ask? The gaming industry is volatile, dangerous, and
extremely competitive. Game studios seem to find themselves in a
perpetual struggle to meet release deadlines, get their games out ahead
of their competitors, and implement the features that players demand,
lest they be left in the dust with a stack of unsold games. This often
results in extremely hurried and sloppy code. Unfortunately, this often
causes serious problems if someone later tries to add an expansion pack
to the game or port the game to another operating system.
12 CHAPTER 1

The Input Subsystem

The input subsystem receives the user’s commands through an input device (like
the keyboard or a joystick) and records these commands for further processing.
While input device programming is not difficult, it should be done carefully,
because flawed input processing can easily ruin an otherwise excellent game. The
first version of Apogee’s Rise of the Triad (a first-person shooter from several
years ago) suffered from particularly bad input handling, and the game was
aggravating to play until this problem was fixed.
One of the input subsystem’s most important jobs is to simultaneously support a
variety of input devices. A well-written input subsystem should be able to
integrate just about any type of oddball game controller with minimal effort (this
is made a bit easier by libraries like SDL, but it’s still something to keep in mind
as you code). Some players prefer to use joysticks rather than mice, and an input
subsystem should be able to accommodate this preference without modification
to the main game code. As far as the game is concerned, the joystick should
appear as a generic device, capable of producing “left,” “right,” “up,” and
“down” commands. We will discuss SDL’s input handling and abstraction in
Chapter 4, and we’ll touch on the lower levels of input handling in Linux later on.
Nearly every game on the market allows you to remap the keyboard and other
input devices to your liking, and this is a feature that players demand. Many
people have non-US keyboards with different key locations, and you’ll end up
cutting off a lot of would-be players unless you allow them to configure the game
to work with their keyboards. Fortunately, this is not difficult; it can be
accomplished with a simple lookup table. It is also a good idea to allow the
player to store and retrieve multiple key mappings, in case a friend prefers a
different configuration.

The Display Subsystem

The display subsystem conveys the game’s status to the player in a visually
impressive way, whether through simple 2D graphics, or advanced 3D rendering
(the type of graphics you use doesn’t matter, as long as they are appropriate for
the game). Regardless of the type of graphics produced by the display
subsystem, the structure of the code is substantially the same.
THE ANATOMY OF A GAME 13

The display subsystem is responsible for taking advantage of the available


display hardware. Serious gamers often equip their machines with snazzy 3D
graphics cards, which can bring enormous performance and quality improvement
to 3D games. However, this performance boost is not automatic and requires
special effort by the programmer, which is usually accomplished through an API
(application programming interface, essentially a big library of routines) like
OpenGL. 3D acceleration is beyond the scope of this book, but we’ll
demonstrate how to get OpenGL up and running in Chapter 4.
Before you can show off your graphics code, you’ll need something to display.
Although it is common for programmers to develop temporary artwork for
testing purposes, few are skilled artists, and they usually find it necessary to
enlist the help of a skilled digital artist to produce acceptable game artwork.
Players are a finicky bunch, and they are most intolerant of subpar graphics.
Game programmers should spend a great deal of time developing a good
graphics engine, and a designer should place a high priority on obtaining quality
artwork for a game.

The Audio Subsystem

Although computer audio technology has not been hyped as much as computer
rendering technology during the past few years, a game’s audio subsystem is
every bit as important as its graphics subsystem. Fortunately, producing
high-quality sound on a computer is not as difficult as producing high-quality
graphics.
Sound is easy to play back (usually a simple matter of a few function calls with a
multimedia toolkit), but creating production-quality sound effects for a game is
as much an art as creating graphics, and should be left to a specialist. Stellar
sound effects can boost a game’s atmosphere, and lousy sound effects can
seriously damage a game’s potential.
3D enhanced audio is one of the latest trends in computer sound technology with
modern sound cards (like Creative’s SB Live! series) supporting four-speaker
surround-sound, and 3D-aware sound-processing to simulate the Doppler effect
and other complex sound wave interactions. (Simple two-channel stereo sound
just falls short of the immersive environments of today’s 3D games.) In fact,
some sound cards can even accelerate these effects in hardware. Several
14 CHAPTER 1

competing 3D sound APIs have emerged, and we will discuss one of these
(OpenAL) in Chapter 5.

The Network Subsystem

Multiplayer gaming is very popular these days, and it is reasonable to assume


that this trend will continue. The network subsystem connects a game to other
computers over a network so that multiple players can participate in the action.
Network programming is not as difficult as it used to be, especially with the
advent of the Internet as we know it. Still, the network subsystem must be
extremely robust and flexible, as, not surprisingly, gamers are rather intolerant
of network failures during games.
Basically, the network subsystem informs the other computers in a network of
the current state of the game so that the players stay synchronized. This can be
quite a trick, and so it is wise to develop the game with network capabilities in
mind. You may find that a networking library such as Apple’s OpenPlay makes
this job a bit easier.
Above all, do not implement network support as an afterthought, because it
often affects the entire design of the game. Decide whether your game lends
itself to netwok play and build this requirement into the fundamental game
design; doing so will save headaches later on when the designer invariably
demands that multiplayer capabilities be added.

The Update Subsystem

Games generally have to track a lot of rapidly changing data, including the state
of the player and the condition of each enemy—information that must be
updated frame by frame to keep the game moving. The update subsystem
manages this data.
The update subsystem is the game’s brain. It enforces the game’s rules for
movement upon the player, “plays” the role of each enemy (which might involve
a certain amount of artificial intelligence), ensures that every object is within the
allowed boundaries, and inflicts injuries. It could almost be said that the other
game modules are merely interfaces to the update subsystem.
THE ANATOMY OF A GAME 15

Keyboard
Mouse I nput Subsystem
Game Pad
LAN or
Network Subsystem Internet

Update Subsystem

3D Hardware /
Framebuffer Di spl ay Subsystem

Audi o Subsystem Sound Card

Figure 1–1: A typical game loop

Although it may be tempting to haphazardly throw the update subsystem into


the game loop (discussed in the next section), do not do so. Game projects tend
to get out of hand quickly if they are not kept in a reasonable amount of order,
and the update subsystem usually grows steadily throughout the development
cycle; make the update system a separate module to begin with. If you don’t pay
attention to code organization, you’ll end up with code that looks like the
500,000 lines of spaghetti behind (no offense, Activision) Civilization: Call To
Power.

The Game Loop

The game (see Figure 1–1) loop is the “glue” that binds the various game
subsystems. It is simply a while loop that runs throughout the entire game,
looping anywhere from 30 to 60 times per second. The game loop invokes the
correct routines to gather input from the player and from the network, updates
16 CHAPTER 1

the status of all objects in the game, draws the next frame of graphics, and
produces audio. While this process may sound complicated, it is actually quite
trivial, because all of this functionality is provided by the game’s input, network,
graphics, and audio subsystems.
The game loop should start as soon as the game’s other subsystems have been
initialized, and should end when the player exits the game. It may be a good
idea to separate the menu system from the main game loop in some cases, but
doing so could actually complicate the game’s code. With a properly written
game loop, a game becomes a “state machine” that acts on its current state
based on the player’s input.
Organization is important too, since the game loop sequences the other
subsystems. This should not be a haphazard decision; for instance, the data
gathered from the networking subsystem often influences the decisions of the
other subsystems, so it should be invoked first. The graphics subsystem should
probably be last, since it reflects the data generated by all of the other
subsystems.
As you can see, a game engine is conceptually simple, but the devil is in the
details. In the next chapter we’ll become familiar with the tools we’ll use for
Linux game programming, and then we’ll start to work with the libraries and
interfaces that make it all possible. If you’re already familiar with development
tools like gcc and gdb, you may wish to skim over Chapter 2 and move on to
Chapter 3 or 4.
Chapter 2

Linux Development Tools

As an operating system created by computer geeks, Linux provides a particularly


nice programming environment. Although it may be a bit intimidating and
confusing at first, it provides a great deal of power after the initial learning
curve. In this chapter we will examine the basic Linux programming tools from
the perspective of a game developer.
If you are already experienced with Linux or UNIX programming, some parts of
this chapter will be of less interest to you. We will cover specific details of these
tools later as we encounter them, so you will not be at a loss for skipping over
sections of this chapter.

Programming Editors
Before we can dive into the subject of Linux game coding, we’ll need a way to
write our source code. Although simple editors such as pico and joe are sufficient
for some simple tasks, they are inadequate for programming. It would be
preferable to use a text editor with support for syntax highlighting, brace
matching, and other features. Let’s take a look at several of the more popular
code editors. If you have never written code with a UNIX-like system, it would
be a good idea to try out these editors to see which one best suits your
programming style. This chapter is not meant to be a reference manual or
tutorial for these editors; rather, it is starting point for those who have never
written code on a UNIX-like platform.
18 CHAPTER 2

vi

vi (pronounced “vee-eye” or “vie”) is a rather old text editor with a strong


following. It is difficult to master, but once you have learned its keystrokes and
its quirks, it is hard to use anything else. vi works well on just about any Linux
configuration; it requires almost no processor power and very little memory. It
also has the nice advantage of being present on nearly every UNIX-like system
you’ll encounter, including most Linux systems. vi is a standard component of
every major Linux distribution.
Although vi is an old editor from the days when everyone worked over slow text
terminals, it has been improved substantially by its users, and some modern
versions (such as vim) are capable of syntax highlighting and other niceties.
Several versions of this editor are also available for the X Window System,
featuring pull-down menus and convenient shortcuts. However, these versions
defeat one of the greatest features of vi: that it can be used over nearly any type
of terminal. vi can be used efficiently over low-speed telnet connections, within
local terminals, and even from Palm Pilots and other unusual devices. Its
minimalistic interface requires very little functionality from the terminal.
Graphical versions of vi throw this feature away and so can hardly be considered
substitutes for the original vi editor.
vi is actually a full-screen interface to the command-based ex editing engine. ex
can also be used outside of the vi editor as a command-line tool, and it can be
used to add editing capabilities to shell scripts. For instance, a shell script might
invoke ex to edit a configuration file automatically. ex commands can be
specified within the vi editor, although a tutorial on the nuts and bolts of ex is
beyond the scope of this chapter.
vi is a mode-based editor, and this is a major source of confusion. vi has two
main modes: command mode and insertion mode. Command mode is strictly for
issuing commands to vi. For instance, one might use this mode to move to a
certain line in the document and delete a word. Command mode may not be
used for typing text into the document. Anything you type in command mode
will be interpreted as a vi command (and indeed there are so many possible vi
commands that nearly anything you type in command mode will do something).
Insertion mode, on the other hand, is strictly for typing text into the document.
Most commands are not recognized in this mode, and anything you type will be
inserted into the document.
LINUX DEVELOPMENT TOOLS 19

vi initially starts up into command mode. To enter insertion mode, press i. To


switch back into command mode, press Escape. This mode switching may seem
like quite a hassle, but it becomes second nature after a bit of practice.

Emacs

GNU Emacs is uncontested as the behemoth of text editors (indeed, some think
of it as an operating system in itself). It is based on its own variant of the Lisp
programming language; almost all of the editor’s functionality is implemented in
customizable Emacs Lisp. Emacs has a loyal following among programmers,
partly because absolutely every aspect of this editor can be changed by the user.
I started writing this book with NEdit, but I eventually switched over to Emacs
because it works well on the Linux console and doesn’t require a mouse. (I’m
also a bit of a Lisp enthusiast, and in that regard Emacs is a perfect match.)
Emacs is not as difficult as vi to learn initially; there is simply a lot more to
learn. Its basic commands and keystrokes are not hard to get used to, but
becoming fluent with Emacs is a major undertaking. Emacs includes a mail and
news client, editing modes for nearly every language you’d ever want to use,
several types of documentation readers, and even optional IRC clients and web
browsers. Many of these features define their own sets of command keys, leaving
much for the would-be user to learn. In return for this hassle, Emacs provides an
enormous amount of power; it’s quite literally possible to set your login shell to
Emacs and never leave its environment.
To get started with Emacs, run the editor (the command is usually emacs), press
Ctrl-h, and then t. The Emacs tutorial will open, and you can use it to learn
the basic keys and editing modes.
In addition to the “real” GNU Emacs, there are several other editors that are
very similar in capabilities and usage. XEmacs1 is a code fork from GNU Emacs
with a number of added features and an improved interface. JED2 is a
programmer’s editor that closely resembles Emacs but has fewer features and a
smaller memory footprint.

1
http://www.xemacs.org
2
http://space.mit.edu/%7Edavis/jed.html
20 CHAPTER 2

Emacs is an ideal editor for people who appreciate a large (perhaps


overwhelming) amount of functionality and don’t mind a bit of a learning curve.
It is excellent for those who would like to use a scripting language to add custom
abilities to their editor (entire applications have in fact been written in Emacs
Lisp). Emacs is available as part of nearly every Linux distribution, and it can
also be obtained directly from the GNU project’s FTP server3 or one of its
mirrors.

NEdit

NEdit, the “Nirvana Editor,” is a very slick code editor from Fermilab.4 It is
neither as absurdly customizable as Emacs nor as ubiquitous as vi, but it is
much easier to learn (since its keystrokes are similar to those of many popular
word processors) and powerful enough for serious work. NEdit’s main downside
is that it requires the X Window System to run. It is a good idea to have at
least a working knowledge of another editor if you choose to use NEdit for your
daily work. This book was written partly with NEdit (though I later switched to
Emacs). Although previous versions of NEdit were encumbered by a license that
was not palatable to most Linux distributors, the NEdit license was changed to
the GNU General Public License with the 5.1 release. The editor is now truly
free software, and it is currently under active development by a team of
volunteers.

Compiling Programs Under Linux


We’re here to talk about game programming, not the basics of C programming,
so we won’t discuss the language itself; however, it’s quite possible that you’ve
never worked with a C compiler under UNIX. This section demonstrates how to
compile and link programs in the Linux (or more accurately, GNU/Linux)
programming environment. There really isn’t much to it; the compiler provides
hundreds of possible command-line options, but most of them aren’t necessary
for our purposes.

3
ftp://ftp.gnu.org
4
http://www.nedit.org
LINUX DEVELOPMENT TOOLS 21

The Nirvana Editor

gcc is the most popular C compiler for Linux. It was developed by the Free
Software Foundation for the GNU project, and it is available on many platforms.
gcc is free software, and it is included as a standard component of nearly every
Linux distribution. There are several other C/C++ compilers for Linux (such as
Kai C++ and the as-yet-unreleased Metrowerks CodeWarrior), but gcc is used
for the vast majority of Linux software development. Some eschew gcc (and its
C++ brother, g++) as quirky or incomplete, but in reality it’s at least as good as
the other mainstream C compilers.
gcc’s basic job is to compile C source code into executable programs. To compile
one or more files, simply pass them to gcc on the command line as follows:

$ gcc file1.c file2.c file3.c

If there are no serious errors, gcc will create an executable file named a.out in
the current directory. Otherwise, you will receive warning and error messages
describing the problems the compiler encountered, and gcc will not produce any
compiled output. If you list multiple files on the command line, gcc will compile
them separately and attempt to link them into one executable, stopping if any
22 CHAPTER 2

individual file produces an error. If gcc is given files that end in .o (object files)
or .a (static libraries), it will link them directly into the executable. This allows
gcc to serve as a simple interface to the linker.

Warning
You may be in the habit of using the shell’s tab-completion feature to
fill in filenames. Be careful when you do this with gcc; it’s easy to
accidentally overwrite your source files by accidentally tab-completing
the wrong filenames. This may seem obvious, but I’ve lost work because
of it.

It is often useful to compile a C source file into an object file instead of an


executable. Object files are not directly executable, but they contain the
machine code translation of the source, and multiple object files can be pieced
together into complete programs. To create object files, supply gcc with the -c
option. This will instruct gcc to skip its final linking phase and to write one
object file for each source file listed on the command line.
gcc is a complex and capable tool, and it supports a large number of
command-line options. We list the most important ones here.

-ansi Disable non-ANSI extensions, such as the asm and inline


keywords. This option might be a good idea if you are concerned
with portability between ANSI C compilers. However, most
programmers aren’t this careful about standards, and strict ANSI
mode tends to break a lot of existing software.

-c Compiles to an object (.o) file instead of an executable. This is


important for creating libraries.

-D symbol Define the given symbol in the preprocessor. This option is


convenient for setting up conditional compilation based on the
system’s configuration. We’ll use it in some of our examples to
switch between different versions of code.
LINUX DEVELOPMENT TOOLS 23

-o filename
Outputs to the given filename instead of the default a.out. For
instance, -o foo will cause the program to be compiled into an
executable named foo (or foo.exe under Windows).

-l libname Attempts to link in the given library, following the standard


library naming convention. For instance, -lSDL would link in
libSDL.so. See the discussion of shared libraries later in this
chapter for more information.

-L path Specifies an additional directory for libraries. For instance,


/usr/X11R6/lib is not normally in the library path, so it is
common for X programs to specify -L/usr/X11R6/lib.

-O n Sets the optimization level (from 1 to 6). The default is to


perform no optimization. It’s reasonable to make a practice of
compiling code with -O2; it doesn’t mess with the structure of the
code too much, and you can still (usually) debug it with gdb. In
some cases this option can really speed up the compiled code.
Finished products should almost always be compiled with
optimization enabled.

-pedantic Enables a strict interpretation of the ANSI C Standard. Compile


with -pedantic -W -Wall if you want gcc to nag you about
sloppy programming.

That’s it for gcc! It has a few quirks and obscure features, but we’ll get to those
as we need them.5 Like most GNU tools, gcc comes with excellent online
documentation. In particular, refer to the manpage or info node for a description
of gcc’s command-line options.

5
Richard Stallman’s book Using and Porting gcc is the authoritative guide to hacking gcc.
24 CHAPTER 2

Using the Make Utility


Most game development projects consist of multiple source files, for the simple
reason that it is impractical to manage thousands of lines of code in a single file.
Since a large project can involve many source files, it would be wasteful to
recompile everything if only one file had been changed since the program was
last compiled. This happens, however, if all of the files are given to gcc at once
on the command line. For instance, the Linux version of Civilization: Call To
Power consists of more than 500,000 lines of C++ code in well over 100 files, and
a full recompile of the entire source tree takes nearly an hour (whereas a partial
rebuild assisted by Make usually takes 15 to 20 minutes).
The Make utility speeds up software development by automatically determining
which files actually need to be recompiled after changes have been made. Make
also eliminates the need to type long command lines to rebuild programs, since it
stores all of the required commands and invokes them as needed.
Although Make has a lot of functionality, its basic usage is quite simple. It is
based on targets, which are sets of directions for maintaining the components
(object files, libraries, and so on) of a program. Targets specify the name of the
component to track, the source files and other targets that the component
depends on, and the commands for rebuilding the target. The instructions for
building a component are called rules, and the list of files that a component
depends on are called dependencies. When make is invoked upon a certain target,
it checks that target’s dependency list first. If any of the dependencies have been
changed since the target was last rebuilt, the target’s rules are executed. Make
also recursively rebuilds any out-of-date targets in the dependency list. This is
extremely convenient for large, modular programming projects.

Creating Makefiles

Make looks for targets and rules in a file called Makefile or makefile. This file
can contain any number of targets. If Make is started with no command-line
options, it automatically attempts to rebuild the first target it encounters.
Consider the following makefile:

program: file1.c file2.c graphics.a


gcc -c file1.c file2.c
gcc file1.o file2.o graphics.a -lSDL -o program
LINUX DEVELOPMENT TOOLS 25

graphics.a: graphics.c draw.c


gcc -c graphics.c draw.c
ar rcs graphics.a graphics.o draw.o
ranlib graphics.a

This file describes how to build an executable called program and a static
library called graphics.a. (Don’t worry about the commands for building the
library—we’ll discuss libraries later in this chapter.) program depends on
file1.c, file2.c, and graphics.a. If any of these have been modified since
program was last built, Make will rebuild program. graphics.a is also a target,
and it depends on graphics.c and draw.c. The indented lines under each target
are rules. If program needs to be rebuilt, Make will execute the two rules that
have been provided. These lines must be indented with tab characters; spaces
will not work. Make is rather particular about syntax.

Variable Substitution

The Make utility provides convenient access to environment variables. Makefiles


can set, combine, and retrieve environment variables as text strings and can
include these variables in targets and rules. It is common to use the variable CC
to represent the C compiler command (which in our case is gcc), CFLAGS to
represent the standard set of command-line options to pass to the compiler, and
LDFLAGS to represent the options to pass to the linker (which is normally just the
C compiler but is sometimes explicitly invoked with the ld command). For
example, the previous makefile can be rewritten as follows to take advantage of
variable substitution:

CC=gcc
CFLAGS=-O2 -W -Wall -pedantic
LIBS=-lSDL -lpthread

program: file1.c file2.c graphics.a


$(CC) $(CFLAGS) -c file1.c file2.c
$(CC) file1.o file2.o graphics.a $(LIBS) -o program
26 CHAPTER 2

graphics.a: graphics.c draw.c


$(CC) $(CFLAGS) -c graphics.c draw.c
ar rcs graphics.a graphics.o draw.o
ranlib graphics.a

As you can see, variables are substituted into the makefile with the $(VARNAME)
notation. This is a literal text substitution, and it takes place before the rule is
otherwise processed. What if you want to add to the end of a variable without
destroying its old contents? You might try something like this:

FOO=bar
FOO=$(FOO) baz
FOO=$(FOO) qux

At a glance, it would appear that the FOO variable would end up with the value
bar baz qux. However, Make does not normally evaluate variables until they
are used (in targets), so FOO actually ends up with the string $(FOO) qux. There
are two solutions to this problem. GNU Make (the default Make on Linux
systems) provides a := operator for assignments, which causes its right-hand side
to be evaluated before the variable is assigned. It also provides a += operator for
directly appending to variables. A more portable solution would be to assign
bar, baz, and qux to three different variables and to combine them all at once:

BAR=bar
BAZ=baz
QUX=qux
FOO=$(BAR) $(BAZ) $(QUX)

This (hacked) solution allows the variable FOO to be constructed correctly when
it is used in a rule. It is a rather ugly way to do so, however, so we suggest using
the GNU Make extensions.
Although the use of variables might lengthen a makefile, they can provide a nice
bit of abstraction. Variables make it easy to modify the options used throughout
the build process without changing the whole makefile.
LINUX DEVELOPMENT TOOLS 27

Implied Rules

Since C files are almost always compiled with the cc command (which is a
symbolic link to the gcc command on Linux machines), there is really no need to
specify build rules for each source file in the project. Make allows for implied
build rules. That is, if a target is followed by no rules and does not specify any
dependencies (or it simply does not exist), Make will attempt to use a default
build rule based on the target’s file extension.
For example, let’s say that foo.c is a C source file containing the function bar
and that main.c is a C source file containing a main function that calls bar.
The following makefile will build the program. Notice that there is no target for
foo.o—it is referenced by the foo target, and Make assumes that it should create
the target by compiling the file foo.c. (Actually, Make knows of several different
source file types, C being perhaps the most common.) When Make automatically
invokes the C compiler, it adds the CFLAGS variable to the command line.

CFLAGS=-O2 -W -Wall -pedantic


foo: foo.o main.c
gcc foo.o main.c -o foo

Phony Targets

Programmers often use Make for purposes other than building executables. It’s
really a general-purpose project management tool. For instance, I’m currently
using a makefile so that I don’t have to delete a bunch of files and then run
LATEX, MakeIndex, and dvips every time I want a preview of this book. Consider
the following makefile:

foo: foo.c
gcc foo.c -o foo

clean:
rm *.o
rm foo

The clean target has no dependencies and is therefore built only when it is
specifically requested on the command line. The command make clean causes
Discovering Diverse Content Through
Random Scribd Documents
“Don’t you believe a word of that ’ere stuff. It’s all gammon, I tell
you. They can do without us a great deal better nor we can do
without them. They’ve got the whole world to resort to, and can git
their supplies anywhere they please.”
“Yes, I know that; but then they haint got anything other nations
want. It was our cotton what brought all the gold and silver into the
country.”
“There’s that old song again. Why, they’ve got the best perducing
land in the world. And their corn and cattle aint to be sneezed at the
world over.”
“Well, that may all be true,” rejoined the other, “but they can’t
whip us.”
“Well, suppose we whip them, what will be gained?”
“Why, we’ll stop the ’tarnal thieves from stealing our niggers.”
“Now that’s a grand mistake. Don’t you see every nigger in the
South will break right for the North, for there won’t be no Fugitive
Slave Law then. And then you know what a dreadful time we had
not long ago up Lowndes county with the niggers, for this here
country’s got twice as many niggers as whites.”
At this an angry dispute arose between them, one declaring the
other an abominable Yankee, and the other is stoutly denying it.
Oaths were freely bandied, and the loyal Southerner threatened to
call the corporal of the guard, and have the other arrested. The
latter in the mean time continued to protest that he had said nothing
detrimental to Southern interests.
“Well, how did you know,” said the rabid secessionist, “about the
cattle and corn in New York, if you had never lived there?”
“But I have been there, though I never lived in that region.”
“Well, if that’s the case,” responded his antagonist, “you had
better keep mighty quiet about it, or we’ll treat you like we did John
Peterson, that miserable Yankee that we hung last week to a pine
tree.”
Just then the relief-guard came, and the conversation ceased. I
noted down at the time the dialogue as it occurred, gave the
manuscript subsequently to my friend Captain Steadman, who, in
connection with other papers, as the reader will presently learn,
carried it to Washington city, where I received it from him.
From all this, which was spoken in a most angry and boisterous
manner, and while I held my ear to the key-hole of the prison-door, I
learned what excessive antipathy the Southern people, as a mass,
entertain towards persons of Northern birth. As the reader follows
me through this book, other evidences of Southern ignorance,
malice, and inhumanity will arise, all of which I witnessed or
experienced, and all of which are related with no spirit of hatred, but
as an “ower true tale.” I do not relate these facts in the spirit of a
politician, nor for political purposes; for the nativity, education, and
political antecedents of myself and of the entire family from which I
sprung, have developed a warm support of Democratic principles. To
these I yet ardently adhere, though positively and absolutely
repudiating that form thereof which in the slightest degree affiliates
with treason or oppression.
CHAPTER V.
Southern Inhumanity—A Prison Telegraph—Mobile—Conversation with a Fire-Eater
—Negro Sale Stables—A Bad Sign—Mule-Beef—Montgomery—In the Penitentiary
—Felon Soldiers—Hanging for Theft—Visit to a Condemned Prisoner—Who Shall
Answer?

Our condition now became so painful and distressing, that, as a last


resort, we determined to petition the authorities for a redress of our
grievances. We had neither beds nor blankets, and the allowance of
rations doled out to us was insufficient to sustain life. A lieutenant in
the Confederate service, a poor, illiterate fellow, not possessed of
education sufficient to call the muster-roll correctly, entered the
prison and threatened to place Major Crockett—of whom we have
spoken before—in irons, simply because he had referred, in the
Lieutenant’s presence, in no very favorable terms, to the character of
our treatment. We had made application personally to Colonel
McClain, then commandant of the post, and who, we learned, was a
professed Christian. We were careful to appeal to his Christianity as
a means of awakening an interest in our behalf. His reply was as
follows:
“You invaders! you abolitionists! you that are stealing our
property! you talk about Christianity! You should be the last men to
utter a word on that subject.”
A lieutenant in our ranks, named Herbert, answered him by
saying:
“If your so-called Southern Confederacy cannot furnish us with
enough to eat, just inform us and we will acquaint our government
of the fact.”
This seemed to irritate the doughty Colonel, and he replied very
fiercely:
“I’ll let you know that we have a government strong enough to
hold you. You will have to go into close confinement.”
In a short time four men with loaded guns entered, and took
Lieutenant Herbert from the prison. What was to be his fate we
knew not, but in five days he returned, his appearance indicating
that he had been exposed to severe treatment. He told me that he
was taken to the old county jail, was there incarcerated in a damp,
filthy, and bedless cell, swarming with odious vermin, and from
which a negro had recently been taken to be executed. This
barbarous outrage was inflicted for the sole purpose, in the language
of his tormentor, “of letting him know that there was a Southern
Confederacy.”
The sick and wounded prisoners in the room above us were
suffering intensely, and we were not allowed the privilege of visiting
them. In order to hold any communication at all with the inmates
above, we were compelled to resort to an expedient which answered
our purpose for the time. We obtained a small wire, and by letting it
down from the upper window to the one below, and attaching a
written communication to it, opened up a kind of telegraphic
connection between the two departments of the prison. In this way
we were daily informed of the transactions of our friends above.
We were now about to leave the prison, and we quitted it, feeling
with Bishop King, that
“A prison is in all things like a grave,
Where we no better privileges have
Than dead men; nor so good.”
We were next taken to Mobile, Alabama. On our way thither, I
conversed with a number of Southrons, among whom was an
insignificant personage from South Carolina. He complained because
their officers were not allowed to have their servants with them. He
called it one of the most inhuman deprivations imaginable!
“Sir,” said I, “we have been treated like beasts and half-starved
here on your southern soil; what do you think of that?”
“O,” he replied, “that’s all right enough for you ’uns; but we
belong to the first families of South Carolina!”
“Your logic is vain, sir, for we of the free North recognize no
officer in the army as made of better stuff than the least drummer-
boy in the service. Your ‘first families’ were the prime movers in this
rebellion, being the degenerate descendants of bankrupt royalists
and luckless adventurers.” The truth cut him severely, and he began
to curse the “mudsills” of the North, ridiculing that pure democracy
which lifts up the poor and levels down the rich. When I referred to
our free schools and our general information as a people, he raved
like a madman. His ignorance boiled over in froth and fury, only to
emphasize the corrupting effects of the bastard aristocracy of the
South.
We arrived in Mobile on Sabbath morning, the 26th of May. Here,
too, we could detect an undercurrent of Union sentiment in the
humane treatment we received. I knew full well, however, the odium
in which the Mobilians held all who opposed human bondage as
legalized in the Confederacy. I felt that we were indeed among
enemies and barbarians. We were driven like yoked bondmen to the
heart of the city, and there halted in the crowded streets for about
two hours and a half beneath a sweltering Alabama sun, after which
we were thrust into the negro sale stables. Of course we were
fatigued and sickened by such outrageous treatment, but we bore it
all as patiently as grace would allow. As we entered these human
chattel stalls where many poor hearts had sorrowed before, we
noticed this inscription over our stable door.
“NEGROES FOR SAIL AND GOOD FEALD HANDS.”
During our stay in this place there was quite a stir among the
rebels. The astounding fact was revealed that the mules slain at
Shiloh had been barreled up and forwarded to Mobile to feed Yankee
prisoners! When this abomination was made known to the
commandant, he immediately ordered the mule-beef to be thrown
into the river; and in order to redeem his government from the
merited contempt of the civilized world, he published the facts in the
Mobile papers. A copy of a daily paper containing the information
was furnished us by a negro, and we had the satisfaction of reading
the history of our rations!
The commandant’s motives in publishing this barbarity were not
appreciated by the chivalrous (?) authorities, and he was himself
arrested and imprisoned for an act that even cannibals might blush
to condemn.
The negroes, who were shrewder and more manly than their
masters, were our faithful friends and news-bearers. They all
understood how to furnish us papers in the manner described in a
previous chapter. The results of the mule-beef investigation plainly
proved that the whole transaction was sanctioned by the
Government. It was not an individual speculation by an unprincipled
army contractor, but an official outrage, perpetrated by the
chivalrous Confederacy!
From Mobile we were taken to Selma, from thence to Tuscaloosa,
and from thence to Montgomery. Here we were placed in the
penitentiary over night, until arrangements could be made for our
accommodation in the military prison. Here we shared the fare of
criminals, which proved to be the best I ever received in Dixie. As to
the truthfulness of the report that the Confederacy had liberated
their felons as soldiers, I am not prepared to speak. But while I was
in the Montgomery penitentiary, during the brief space of thirty
hours, two inmates were released and paid eight hundred dollars
each to enter the service as substitutes. This I witnessed. The
keeper of the prison informed me, on inquiring the nature of their
crimes, that they were murderers. From reliable sources I learned
that many criminals, from different southern prisons, were received
into the army as soldiers. The two I saw were desperate-looking
men.
While here I was deeply impressed at seeing a negro in an
adjoining cell under condemnation of death. In order to frighten him
to make such confessions as his accusers desired, the rope with
which he was to be suspended from the gallows, was put in the cell
with the culprit. I asked the keeper the nature of the man’s offence,
and was told that he was sentenced to die for stealing a watch.
“What! are you going to hang a man for stealing a watch?”
“O, yes,” said my informant, “we must be severe with these
niggers, or we couldn’t live for them.”
“But he is a valuable-looking piece of property.”
“True, sir, but the State is obligated to pay one-half his value to
the master, and he was appraised at sixteen hundred dollars,—so
you see only one-half the loss will fall upon his master.”
All this was spoken with that serious business air which showed a
real sympathy with the slaveholder who was about to suffer the loss
of eight hundred dollars!
On account of my crippled hand and general debility, I was
privileged to walk about the hall. There I could see the doomed man
who was so soon to suffer the ignominious death of the scaffold.
The keeper’s sympathy was altogether with the owner of the negro;
but he congratulated himself in the master’s behalf by saying that,
since the beginning of the war, negroes were poor sale, and that for
the owner of this condemned one to get half his appraised value
would be very consoling in the hour of trouble! One circumstance in
connection with this incident gladdened my heart. On one occasion I
overheard two men conversing with the negro in his cell. They were
godly men, and had come to offer the sympathy of supplication in
prayer. One of these visitors was gifted in a special manner. His
pleadings before the court of heaven in behalf of his unfortunate
fellow-man, were touchingly eloquent. He sang and prayed
alternately, and with tearful eyes and tender tones, pointed the
criminal to the Saviour who blessed the dying thief on Calvary. But
all his instructions and persuasions seemed alike in vain. The stoic
prisoner remained hard-hearted and unmoved.
I asked and obtained permission from the keeper to speak a few
words to the man so soon to die. The conditions on which I obtained
the favor were that my instructions should be given in the keeper’s
presence.
Looking through the iron bars at my sinful but unfortunate
auditor, I said,
“Do you believe that Christ died for all?”
“I don’t know, massa,” he replied.
“Well, you know something about the Bible, don’t you?”
“No, massa.”
“Have you never heard the Gospel preached?”
“Yes, massa, I used to hear old parson Cooper preach, and I
guess dat was what he preached about.”
“Can you read?”
“No, massa.”
“Did you ever pray?”
“No, massa. I’se heard folks a-prayin’. My massa never prayed like
dis nigga,”—referring to the visitor who had been praying with him in
the cell.
“Well, my dear fellow, you know you have to die, don’t you?”
“Yes, massa.”
“What do you think will become of you when you die?”
“I dun know, massa.”
“Did you ever talk with white people on this subject?”
“No, massa.”
Here our conversation was interrupted by the keeper, who told
me I must return to my cell. I had no further opportunity to
converse with the poor negro prisoner. My thoughts troubled me. I
reflected on the destiny of these immortal beings, thus oppressed in
body and soul by their tyrant masters. What a fearful weight of
responsibility rests somewhere! Who shall give account in the great
day for the ignorance of the four millions of slaves, going up to
judgment from a land of boasted light and knowledge? This slave
was a representative man. Although he knew little about secular
matters, he had opportunity to learn even less of religion!
But despite all the efforts to keep the slaves in ignorance, both by
legal enactments and tyrannical vigilance, very many of them gained
a surprising fund of information. What an accursed system of wrong
is that which locks the Bible from the homes and hearts of the poor!
May the uttermost overthrow come upon an institution that prohibits
the education of any class or color of God’s children!
The next day, before leaving the prison, I asked permission to
visit the colored convict once more, but the privilege was not
granted. That very day a dark man was hung, and a darker crime
registered in the book of Judgment-day accounts, the penalty of
which will by-and-by rest upon the head of the guilty perpetrators.
CHAPTER VI.
A New Prison—Murder of Lieutenant Bliss—In Irons—Yankee Ingenuity—Rebel
Ignorance—Parson Rogers—Faithful Servants—Bold and Successful Escape of
Prisoners—Captain Troy—A Blindfold Journey—A Traitor.

We were now conducted to our new quarters in the military prison, a


description of which I will attempt. The side walls were of brick,
twenty inches in thickness, and thirteen feet high. The ends were
closed by massive ironclad wooden gates, extending the whole width
of the prison. The room was about two hundred feet long, and forty
in width. It was used formerly as a cotton depot. There was on
either side a narrow shed-roof, sloping inward, extending two-thirds
of the entire length of the building. Beneath this shelter were six
hundred soldiers, and about one hundred and fifty political prisoners.
Near this prison, Lieutenant Bliss, of Illinois, one of the noblest
and truest men I ever knew, and a minister of the gospel, was
murdered. The circumstances of this cruel outrage are as follows:
One beautiful morning in May, the Lieutenant, being somewhat
indisposed, and desiring to breathe the fresh and fragrant air
without our prison walls, asked permission of the Captain of the
Guard, to go to an adjacent house and get his canteen filled with
fresh milk. With considerable reluctance the privilege was granted,
and the Lieutenant and myself were allowed to go on our errand,
under a guard of four armed men. Upon our arrival at the house,
Bliss handed his canteen through the window, where a lady received
it, and in accordance with his request, filled it with milk, and passed
it back to him. At this moment, one of the guards muttered some
undistinguishable order, which I was unable to understand, although
I was nearer the guard than Bliss. The command, whatever it was,
of course could not be obeyed; but the guard instantly raised his
gun. Bliss saw it, and remarked pleasantly, though a little excited:
“You are not going to shoot me, are you?”
No sooner were his words uttered, than the gun was fired and the
bullet pierced the heart of my gallant comrade. His last words were,
“Brother, I’m shot!” I stood amazed and dumb with indignation over
the bleeding corpse of my faithful companion, the three remaining
loaded guns pointed at me. From this scene of murder I was forced
back to the prison. I felt it my duty to report this inhuman act to the
commandant, and ask redress, by having the reckless guard
punished. What was my astonishment and indignation to learn,
afterward, that that very guard, for that very act, was granted thirty
days’ furlough as a reward. The only apology offered was, that
possibly the guard misunderstood his instructions! I ventured to tell
the commandant, Captain Troy, my opinion of such conduct, and to
his face called the outrage by its proper name, a bloody murder,
committed under his guilty authority. As I might have expected, this
plain language brought down his vengeful wrath, and he replied:
“I will put you in irons, sir.”
I could but reply, thinking of my dear, lost comrade:
“I am in your power, sir, irons or no irons; but you murdered my
sick friend, and are guilty of shedding his blood!”
For my impertinence, I was handcuffed and made to suffer the
cruel spite of my hateful enemies.
These things occurred in the city of Montgomery, Alabama,
among the chivalry of the South.
We often suffered for water in this cotton-shed prison. Some of
our boys resolved to dig a well within the walls. In digging, they
came to a stratum of potters’ clay, by which, after the well was
completed, they passed many a leisure hour in manufacturing little
wares, such as pipes, rings, cups, &c., all of which found a ready
sale among the rebels, and commanded a fair price in Confederate
shinplasters. The ingenuity of our Yankee boys was a constant
marvel to the stupid Southrons. We received sufficient pocket money
by our manufactures to furnish us with many little conveniences and
comforts. One of our comrades, who had formerly been an engraver,
and who had no conscientious scruples about using the rebel
currency to the best advantage, was very skilful in changing five
cent scrip to fifties, and many of the fives that were passed in for
our wares, passed out fifties for gingerbread!
One day quite a commotion prevailed among the rebel peddlers in
our prison. A gaunt, gawking fellow had received one of these
changed bills, but was not quite satisfied of its genuineness. A
motley crowd were huddled around him trying to unravel the
mystery. I was called by the holder of the bill to explain. Said the
puzzled critic, holding out the suspected paper and pointing to the
redundant cipher at the right of the five:
“Look here, Capt’n, at this tarnal round thing here. This thing
ortn’t fur to be here.”
“Well, sir,” said I, “I can’t help it; why did you put it there?”
“I didn’t put it thar, nuther. I got it uv that thar feller,” said he,
pointing to a bright-eyed soldier about seventeen years of age, who
sat looking on with apparent indifference, but who was greatly
enjoying the confusion of the ignorant butternut, who had just sense
enough to know that something was wrong, but no ingenuity to
detect the imposition. I do not justify this money-making trick, but,
under the circumstances, its sinfulness is somewhat diminished.
We were then more than a thousand miles from home,
surrounded by a bloodthirsty and infuriated mob, robbers of our
government, and oppressors of our fellow-men. We were dragged to
that prison half-starved and moneyless. Our rations consisted of a bit
of spoiled beef not larger than your two fingers, a small slice of
coarse corn-bread without salt, and this only twice a day. Whatever
more than this we received, we were compelled to buy at fabulous
prices. While in Montgomery I became acquainted with a clergyman
named Rogers, a member of the Methodist Church South, who had
spent many years in the itineracy, and who was a chaplain in the
Mexican war. Mr. Rogers was a man of fine talent, vast experience,
and apparently of great piety. He had been an intimate friend, in
other years, of Parson Brownlow, which circumstance made his
acquaintance an interesting one to me. He had been arrested, and,
without a trial hurried from his motherless children to this gloomy
prison. The old divine gave me an account of some of his sufferings.
He had been frequently imprisoned for his loyal sentiments; and in a
few instances made hair-breadth escapes from lynching. While he
was in prison he preached for us. The gospel sound was glorious to
hear, even beneath the cloud that rested upon us. Though in bonds,
we could listen to the voice of truth—the truth that makes us free
indeed.
I was here again amused and benefited by the ingeniousness of
the colored people, of whom so many wiseacres are constantly
seeking to prove a natural imbecility. Very often these shrewd
observers would anticipate our wants, and bring us such articles as
we really most desired. Sometimes an apparently careless lounger
would lean himself against our prison-gates, as if to rest himself, and
while facing the guards, his skilful fingers would slip a file or a knife
through some small aperture to an inside Yankee. These implements
were always in demand for the purpose of making rings and trinkets
from refuse beef bones. And in case of a contemplated escape from
prison, such helps as these are invaluable. It was a constant
perplexity to the “Clay-eaters,” to see the negroes so well posted on
war matters. Though the unhappy race have been downtrodden and
abused to an outrageous extent, which nothing short of eternity will
adequately punish, yet they are more intellectual and virtuous than
the majority of the whites in Secessia. With Anthony Benezett, the
philanthrophic Quaker, I sincerely declare that I have found among
the negroes as great a variety of talent as among a like number of
whites; and I am bold to assert that the notion entertained by some,
that they are inferior in their capacities, is a vulgar prejudice,
founded on the pride or ignorance of their lordly masters, who have
kept their slaves at such a distance as to be unable to form a right
judgment of them.
While we lay in this old cotton-shed, thirteen of the prisoners
conceived and executed a plan of escape. They succeeded in scaling
the walls, and wandered about the country for some time; but being
unacquainted with the geographical features of the locality, were all
subsequently recaptured, and again brought to the prison. For this
attempted escape, several were shot, and others were loaded with
huge chains. In the midst of this severe punishment they never once
repined, but looked forward with ardent hope to a period when they
might again be permitted to defend the ensign of liberty they so
dearly cherished. Many who had previously been “conservative” in
their views of the peculiar institution, now realized a modification of
their sentiments, while the universal conviction seemed to be that
this system of human bondage had been the parent source of all our
national dissensions.
Captain Troy seemed to derive special delight in practising almost
every species of deception upon the defenceless prisoners. He
frequently cheered us with assurances that our imprisonment would
soon terminate, and that we would be on our way homeward in a
short time. All these hopes would as quickly give place to saddening
disappointments, for in none of his declarations was there the least
shadow of truth! One day he entered and told us that we had been
exchanged, and ordered us to immediately prepare for our
departure. Then we realized “how deep a gloom one beam of hope
enlightens,” and in our fancy, already treading the soil of liberty, lost
no time in making all necessary preparations to quit the land of
chains and cruelty. Nor had we much to prepare—a few moments
only, and we stood ready for our exodus. The minutes dragged lazily
on that were to introduce us to freedom; but what was our
unspeakable vexation and chagrin to learn that we had been the
victims of a cruel hoax, perpetrated through sheer diabolism.
One bright and beautiful summer morning, however, legitimate
orders came for our instantaneous departure, and, as before, we
were soon ready. At eleven o’clock, we stepped aboard the cars, and
were soon whirled from this Sodomic city to await the gradual
developments of our destiny unknown. Two hundred and fifty miles
brought us to the city of Columbus, Georgia, on the Chattahoochee
river. The crowd that met us here was composed of remarkably
coarse material, and as far as we could perceive, seamed to be an
average of the staple human product in that locality. They saluted us
with such epithets as “blue-bellied Yankees,” “dirty nigger-thieves,”
&c., exhausting the entire slave-pen vocabulary, the reigning
vernacular.
I regret that I am compelled to record the defection of one of our
party, whom we had supposed to be in hearty sympathy with us,
but, who, as the sequel will show, was co-operating with the enemy.
Our first suspicions were aroused by the tender regard shown him
by the rebel officials and ladies; but when we came to Columbus, his
designs and character became more and more apparent. Of him we
shall hereafter speak more at length.
The city in which we had temporarily halted quartered a large
force of rebel soldiers, the majority of them better clad than any we
had yet met. The place itself, extending one mile and a quarter in
the direction of the river, and about half a mile toward the interior,
and numbering a population of nearly nine thousand, was a beautiful
one. I observed a number of unfinished buildings, erected most
probably before the war, but now standing exposed and weather-
beaten, with no roofs to protect them from the sun and rain. The
people here seemed determined to prolong the war to the last,
confident of ultimate success.
CHAPTER VII.
Macon—A Southern Unionist in the Rebel Army—Beneath a Georgia Sun—
Secession Speech—Thoughts of Home—Political Prisoners—Horrible Place—Offer
of the Gospel—Lieutenant A. P. Collins—Contemplated Escape—Robes of Blood!
—Pinning a Federal Soldier to the Ground.

We were next taken to Macon, Georgia. Traveling by night in box-


cars, we had little opportunity to see the country. We were much
annoyed on this trip by drunken, profane, and sleepy guards. Their
cuffs and curses were almost too intolerable to be borne.
On board the train, however, there was one companionable and
intelligent gentleman. I regret that I cannot record his name, for he
was a worthy man, and a lover of his country. He related to me
many strange inconsistencies of rebeldom. Said he:
“I am here in the army. I was a Douglas Democrat, and opposed
this war until my life was threatened. My only alternative was to
become a soldier. You may think your case a hard one, sir, but I
would readily exchange with you, for then I should not be compelled
to fire upon any who rallied beneath the stars and stripes. I was in
the Mexican war, and there followed the dear old flag until it floated
proudly over the metropolis of the enemy.”
He also informed me that he had a family dependent upon him
for a livelihood, and complained of a government that paid eleven
dollars a month to soldiers, and allowed fifty dollars per barrel to be
exacted for flour, and all other necessaries in proportion. Pointing to
his coarse shoes, he said:
“These cost me eleven dollars; this flimsy clothing I wear cost ten
dollars a yard! Once times were good and we were content and
happy; but now my family is suffering, and I know not my own fate.
I know not whether you are a Christian or not; but, sir, my hope is in
the Lord. He knows my heart; and although I am compelled to do
what I believe to be wrong, I feel that God will forgive me for my
family’s sake.”
He was a member of the Methodist Church South, an uneducated
man, but honest and humble. He remarked that, if our conversation
were overheard, we would both be in danger of immediate death.
The morning light appeared at last, and we were passing through
a level, boggy country, very thinly inhabited.
Soon after dawn, the long, shrill scream of the locomotive
announced that we were approaching a place of some note. In a few
minutes we were in Macon depot; but of our destiny or doom we
knew nothing. At this time there were about six hundred of us. Not
until ten o’clock were we permitted to move, hungry and hampered
as we were. Then we were taken from the cars, and for the first
time set our feet on the traitor-cursed soil of Bibb county, Georgia.
In a short time we were driven, like a herd of mules, to the fair-
ground, an area of three acres, surrounded by a picket-fence. Within
were several large, rough, wooden buildings thrown together for the
purpose of holding Yankee prisoners.
It was now the 29th of May, and the noonday heat was intense.
They kept us sweltering in the broiling sun for more than two hours,
and our sufferings were excessive. Suddenly the attention of the
crowd was attracted by a pompous-looking individual, who mounted
a stump in the enclosure, and began, with violent gesticulations, to
harangue the prisoners.
The substance of this speech is herewith appended, though I
confess my inability to transmit it in the patois in which it was
spoken. It is reported to serve as a specimen of the average of
Southern logic and oratory, such as often harried our unwilling ears:
“Prisoners, you have been committed to my charge, and you
know that you are invaders of our soil. You have been stealing our
property, and running them off to Canada and other places. And
when we appealed to you to deliver up our slaves, you passed
liberty bills in your States, nullifying a law that had been passed by
the legislature, declaring that you would not regard the Fugitive
Slave Law. We, in assuming the position we now do, are acting as a
safeguard to our slaves, and protecting them as our property—
property to which we have the right guaranteed to us by God
himself, when he said, ‘Servants, be obedient unto your masters.’
But you of the North have violated the Word of God, and the
Constitution of the once United States. When we asked to secede
from you, giving you all your rights, and demanding only our own,
your government waged an unholy war against us—have carried it
into our country with all its carnage, destruction, and bloodshed.
The God of battles is turning all things in our favor, and we are
driving your army from our soil—taking your men prisoners, which is
your own sad experience. Now, prisoners, you are in my charge, and
I am sure you cannot expect me to treat you only as invaders of our
soil, and murderers of our countrymen. Notwithstanding all this, I
shall try to do the best for you, as poor unfortunate prisoners, that
the conscience of a brave and gallant officer would allow him. While
you obey my orders strictly, you shall not suffer. But if you disobey
them, you must expect to take the consequences.”
After this address, embodying so much profundity and wisdom,
we were surrounded by a heavy guard, and taken within the guard-
lines located on the grounds referred to.
What a dreary spot for our abode, to be endured we knew not
how long! A gloomy, dismal pen was to be our habitation. The only
shade afforded us was that of a few straggling pine-trees, beneath
which we sat at times, brooding over our forlorn and desolate
situation. Oh! how wearily passed the days! how sadly the nights!
How much did our thoughts revert to the “loved ones at home,” and
how in imagination did we realize the loneliness of their sorrowing
hearts!
Mr. Rogers—before spoken of—came and informed me that a
group of men standing at a little distance were from Tennessee and
Mississippi, with several of whom he was well acquainted, and asked
me to accompany him to where they were. I did so, and learned that
there were seven hundred from those States in prison, many of
whom had been incarcerated ten or twelve months without any
change of clothing, or any comfort to relieve the gloom and
monotony of prison life. Among them were lawyers, doctors, and
clergymen—persons who had been accustomed to the luxuries of
refined society, and the endearments of home. A volume might be
written, recording the reflections, sufferings, and experiences of
each of these brothers, shut up there in a loathsome prison for
faithful adhesion to their loyalty. During that night I slept but little,
and said less. My mind was busy in contemplation.
Mr. Rogers conducted me the next night to a long board shanty,
which was used as a hospital for the sick and wounded. When I
entered, my heart sickened at the awful sight presented. There were
confined within that rough wooden enclosure about one hundred
sick and dying, with nothing upon which to rest their aching heads.
We began the work of contributing as much as possible to their
comfort, and of alleviating their sufferings. Most of them were
victims of typhoid fever. We had no light to guide us, and the only
way we could distinguish the dead from the living was by touch.
From time to time was it our painful duty to carry the dead bodies of
these, our fellow-prisoners, and lay them upon the grass, where
they would often be suffered to remain two or three days, when,
being tumbled into rough boxes, they were put upon a dray, and
taken we knew not whither. This night was one of gloom, loneliness,
and desolation. Our bed was the hard floor, and sleep was too “coy a
dame” to be won to conditions so comfortless and lorn. I lay longing
for the morning which came at last; and never did I greet the light
of day more joyously than the 30th of May, 1862. This was my first
night in Macon, Georgia, among the sick, dead, and dying. The place
or pen thus used for a hospital, and the ground enclosing it, were of
such limited dimensions, that the large number of men found it
impossible to be other than exceedingly uncomfortable, and their
clothes became infested with bugs and vermin.
The night of the 30th passed wearily away, and ushered in the
Sabbath—“soft halcyon on life’s turbid waters.” The other ministers
sought to hold a meeting, and I went to the commandant to obtain
his consent, which, he granted. With a light heart, I returned to my
brother ministers to report my success. A moment after, a note was
handed us, stating that no religious services, public or private, would
be permitted. After the lapse of a brief period, they concluded to
send their own chaplain to preach to us. But we declined to hear
him; and I was appointed to give our reasons therefor, which I did
as pertinently as possible. They then threatened to force us to
become listeners to sentiments which were utterly incompatible with
our views of patriotism and Christianity. But they parleyed, and
finally desisted from their threats.
It was here that I first became acquainted with Lieutenant A. P.
Collins, a gentleman of refinement and culture, and with whom I
was destined afterward to share incredible sufferings and perils. He
was a religious man, and a graduate of the Ohio Wesleyan University
at Delaware, Ohio. He had in his possession a portion of the Old and
New Testament, and with this volume it was our wont every day to
repair to the shade of the pine-trees for meditation, reading, and
prayer. The idea of escaping from our horrible imprisonment, which
was every day growing more and more severe, seemed to enter
both our minds at about the same time, and we agreed to make it a
subject of special prayer. We shrank at the thought of abandoning
our comrades in distress; but the hope of life, and the possibility of
again striking a blow for justice and right, stimulated us while
contemplating such a daring and dangerous project. We looked upon
the height of the picket-fence that environed us, the vigilant guard
of four hundred men that watched our every movement, and the
battery of artillery planted within the enclosure, and our hearts
oftentimes sank within us. But our friends were dying around us,
and day by day we saw them deposited in rude boxes, hurried for
ever from our sight. Once we relinquished our hope of personal
deliverance, and determined to remain with our brethren, and, if
necessary, die with them. Many who perished there were noble men,
though they passed away “unwept, unhonored, and unsung.” We
now concluded to continue our prayer-meetings in the hospital. In
this work we seconded the efforts of the Rev. Mr. Rogers, Dr. Doke,
of East Tennessee, and Dr. Fisk, of Illinois. We had not acquainted
these gentlemen with our plans. Their names should never die, for
“Midst fawning priests and courtiers foul,
The losel swarm of crown and cowl,
White-robed walked these noble men,
Stainless as Uriel in the sun.”

Their deeds of mercy were too many for record here. No


circumstances too repulsive, no night too dark, no duty too onerous,
but they were ready for every good word and work. Where suffering
and pain were, there were they present to alleviate and sympathize,
and many a poor fellow, now gone to his long home, blessed them
for prayers and consolations in the night of death.
These noble philanthropists determined to ask for something to
mitigate the sufferings of the prisoners, and accordingly made an
appeal through a humane surgeon for some bedding on which the
dying men might rest. This man carried the message to the
commandant, Major Rylander, but that dignitary utterly refused to
listen to the appeal. The surgeon then endeavored to awaken his
humanity and Christian feeling; but he replied to all this, by saying
very emphatically:
“Sir, I have laid off my robe of righteousness, and put on one of
blood, and the best way to get rid of these d——d Yankees is to let
them lay there and rot.”
Such was the conduct of this man Rylander.
We were compelled still to submit to our fate, though we
employed every effort in our power to alleviate the sufferings of our
dying friends. One case, in particular, attracted my attention. A
political prisoner named Foote, who had formerly been a captain of a
steamboat plying on the Florida rivers, being suspected as a Union
man, was arrested and thrown into prison. He was occasionally
visited by his wife, and so careful were the rebels, notwithstanding
their boasted superiority, that two guards with loaded guns were
invariably detailed to dog the footsteps of this woman. A system of
perfect espionage was constantly maintained, and so suspicious
were the rebels of each other, that they would not permit a single
guard, in any case, to accompany a prisoner. An instance of the
most barbarous torture it was ever my lot to behold, I witnessed
while here. It was inflicted upon a young man from Illinois, for some
offence unknown to me. He was taken and stretched upon the
ground, face downward, his legs and arms drawn as far apart as
possible, and then pinned to the ground by driving stakes across
them; and in this state of terrible torture was he left for twenty-four
hours.
Acts like these filled our hearts with the most gloomy forebodings,
and we began to seriously deliberate the propriety of consummating
our previously contemplated escape. We were about three hundred
and fifty miles from the nearest point where the stars and stripes
could be reached by water, and two hundred and eighty miles by
land. The distance seemed to be insurmountable, to say nothing of
the impossibility of surviving the hot weather. But the hope of liberty
gave zest to the project, and we determined at once and for ever to
abandon the scene of so much horror and misery.
CHAPTER VIII.
Preparing the Way—Dave—Pepper, Matches, and Fish-hooks—Exchange of
Clothing—Passing the Guard-lines—Frightened Horse—Halted—Passed—In the
Woods—Hidden in the Swamp—Pursued—A Night Journey in the Cane-brake—
Manna.

We resolved to select a dark and rainy night to put into execution


our long cherished plan, and we waited anxiously for such a night.
The morning of the 1st of June, which was the anniversary of my
twenty-ninth birth-day, brought with it deep and long forgotten
memories of other days.
The next day I was attracted by the movements of the old negro
Dave, who was employed in the menial services of the prison. He
was evidently well acquainted with our position, and knew all about
the state of affairs. As he passed near me, he gave me a significant
grin, hung his head in assumed diffidence, and began shoveling
among the rubbish with all his might, saying to me as he labored,
just loud enough for my ear, but looking all the while at his work:
“You Yankees has jis made about a tousand of the drefful rebels
bite the dust up in Tennessee. I golly, I’se glad!”
“Why, Dave, aren’t you a rebel, yourself?”
“No, sah, massa, I’se—”
Just here, a straggling rebel official sauntered in sight, and our
conversation was interrupted. If any Federal prisoners were
discovered holding private consultations with the slaves, there was a
death penalty just so adjusted in the martial laws of the
Confederacy, as to meet the case. I let the day pass without further
effort to see Dave.
The next day, however, finding a favorable opportunity, I asked
Dave if he could furnish me three fish-hooks.
“God bless you, massa, yes!”—his eyes snapping fire as he
responded.
“Can you get me a tin full of salt, and a paper of pepper?”
“Yes, massa!”
“Can you get me a box of matches?”
“Yes, massa; but how’s I gwine to get ’em past the guards?”
“Try, Dave, won’t you?”
“Bless your soul, massa, yes!”
I gave him the money, and when his chores were done, he
passed out, apparently one of the most stupid darkies I ever saw.
Fortunately our conversation was not overheard, and I soon was in
possession of the desired articles.
During the day, I visited a Tennesseean—a political prisoner—and
proposed to exchange clothes with him, to which he at once
assented, suspecting my object. He promised to be true, and reveal
nothing. We agreed upon an hour when he should visit my quarters,
at which time we were to exchange our clothing. I then informed
Collins what I had done, and he made a similar arrangement with
another Tennesseean.
Time passed wearily on, and brought the night of the 18th of
June,[A] which was dark and rainy, and promised fairly for our
proposed adventure. In due time our United States uniform was
exchanged, and we were clad in rebel rags. Our hearts beat high
with hope, and we were resolved to escape or perish in the attempt.
About half past eight o’clock, we slowly crawled out of the prison
—Collins a little in the rear.
This, with the exception of crossing the guard-lines, we
apprehended would be the most dangerous part of our undertaking,
and our movements were consequently slow and cautious. We
continued to advance, keeping within whispering distance of each
other, until we reached a little clump of pines near the fence, which
point we had previously selected as a rendezvous. Here we paused
to make further arrangements. We felt certain, now, that if we were
discovered, we would be shot. Life for us was only in pressing warily
forward. After a minute’s consultation, in the lowest whispers, it was
agreed that I should take the advance, and that should I be
discovered, and shot, he should return to his quarters; but if I
succeeded in passing the guard-lines, and reaching our second
rendezvous—a thicket of fallen bushes between the guard-lines and
picket-fence—I was then to announce my success by a single clap of
the hands, which would be a signal for him to follow.
I accordingly lay down on my face, and crept quietly outward
through the lines. The intense darkness prevented my seeing a
guard, who chanced to be stationed close to my path. I came within
six feet of him, and could distinguish that he was reposing carelessly
against a tree, playing with the rammer of his gun, the noise of
which served to keep me from running against him. It was the most
thrilling moment of my life! But I soon got beyond the sound of the
clicking ramrod of an enemy whose business it was to shoot just
such adventurers as myself, and I began to breathe a little more
freely as I neared our second rendezvous. In a few minutes I was
safe outside the lines, and snugly hidden beneath the dark foliage of
the tangled bushes. Just as I was about giving the signal to Collins, I
discovered that I had frightened an artillery horse so much, that he
broke loose from his hitching-rack, and in another moment it
seemed as if all rebeldom were out in pursuit of him. Now I should
be discovered! To run or lie still would be death. An unseen Deliverer
gave me presence of mind. I resolved to turn rebel for the time
being, and assist in catching the horse. My life depended on the
action of that moment. I ordered all the rebels astir, assuming as
best I could the arrogant Southern tone of authority, to assist me in
securing the animal, and had the gratification of seeing him caught
and led away, wondering whether that would be the last of the
“catching” to be done that night! Again I started for our place of
rendezvous; but being somewhat excited, and the darkness and rain
of the night adding to my bewilderment, I ran against an artillery
guard, who instantly exclaimed:
“Halt, dar!”
My unseen Protector again aided me, and I once more assumed
the rebel tone and manner. I replied, with as much offended dignity
as my beating heart would allow:
“Halt, whar?”
“Who are you, sah?”
“Have you been here so long, sir, and don’t know me yet? What’s
this mean, sir? Don’t you understand your business, sir?”
“O, yes, sah, I know you, now; you ’long to that thar battallin
over thar. Go on, sah!”
Soon after this, I succeeded in reaching our appointed place of
meeting, but believing that the confusion of the guards in capturing
the frightened horse had prevented Collins from attempting to
follow, I went down to the fence alone. Five minutes later, I heard
my comrade giving the signal at the outer rendezvous, to which I
instantly responded, and in a very few minutes we were both
outside the picket-fence, on the dismal banks of the Ocmulgee river.
We traveled fifteen miles before sunrise, and, just at daylight,
crossed the river on a railroad bridge, leaving it between us and our
enemies. It was a glorious summer morning. The birds, all beautiful
and free, were chirping their matin praises. The fields and forests
were fragrant with the blessed baptism of dews, and glittered in rare
brilliance before the rising sun. All nature was clad in robes of
royalty, and voiced to sweet anthems of rejoicing. But we were
weary wanderers, homeless and hated, fallen among thieves and
robbers in the midst of our native land. As the daylight grew
stronger, we resolved to secrete ourselves in the thicket among the
croaking frogs, and lie low in the dense undergrowth among the
reptiles of the cane-brake. We were destitute of provisions. In our
haversacks were the matches, salt, pepper and fish-hooks. We
kindled a small fire, and burnt our papers. We did this regretfully, for
we had some valuable notes and memoranda among them, but we
chose to suffer their positive loss, rather than risk the danger of a
recapture with them still in our possession. It was a sad sacrifice, in
a solitary sanctuary, on a strange altar. Yet our safety demanded it,
and it was done.
Our situation was now both desolate and dangerous. We were in
the midst of a vast cane-brake, the extent and surroundings of
which were altogether unknown to us. The tall, straight cane-
growths, like steady fingers, pointed upward to a land of liberty on
high, and we knew a Present Guide thither, but we were without
chart or compass in this lower wilderness.
About three o’clock in the afternoon, we ventured to the road,
keeping a vigilant lookout in every direction, dreading the sight of
white men, and ardently hoping to see the face of some lowly slave,
in order to arrange with our ever-faithful friends and now brothers in
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!

ebookgate.com

You might also like