Norbert Cartagena -
The Linux gaming scene is not as robust as certain other operating systems, I will admit. However, the myth that there are no popular games published for the Linux platform is a thing of the past. The truth is that there are now companies publishing games for Linux. There are also Open Source projects focusing on the issue of video games, most of whom welcome assistance from anyone who offers, especially in the 3D gaming arena. Below, I cover a couple of the most interesting recent developments in the Linux gaming world. More importantly, I will introduce some of the concepts and tools involved in 3D game programming under Linux. Note that this is not a tutorial on how to program, just an introduction to some of the projects, tools and sources of information involved with the field. For those of you who are serious about learning, I will list a number of books and other sources where you can get more information on the subject. For those of you who are not, then enjoy the article anyway. You might just learn about something you didn't know that you didn't know.
Porting or emulation?
When I'm not in front of the computer, you can usually find me wandering up and down the computer section of the local Barnes and Noble. Almost every time go, I meet people who are interested in Linux for one reason or another, usually some techie looking for a new toy or someone who wanted to find information on "this Linux thing" they heard someone talk about. When talking to them, if they know anything about Linux, I'll normally get a lists of "can I do this?" questions, ranging from office suites to digital cameras to streaming video. A comment I'm constantly receiving is, "Yeah, it sounds great, but there are no popular games for Linux." Until recently, my answer to that was to talk about Loki and their newest game ports or about a friend who just got some Windows game running under WINE. A couple of months ago, that all changed.
Given the events that took place late January, one would think that commercial gaming on Linux would be a thing of the past. That month, the Linux world received a major blow as Loki Software, once the sweetheart of the Linux gaming scene, closed its doors to the world. Though this was a tough loss, it was not a death blow to the community, at least not if TransGaming has anything to say about it.
Both companies are responsible for bringing a number of popular formerly Windows-only games to Linux. Loki went about bringing games to Linux by porting them to Linux-native code. TransGaming, on the other hand, has taken the increasingly popular emulation road, using a modified version of WINE, called WineX. This is in line with a number of recent developments in the Linux application expansion, as can be witnessed by CodeWeavers' newest application, CrossOver Office, which uses WINE in allowing Linux users to use two formerly unattainable pieces of software on the platform: Microsoft Office and IBM Lotus Office Suite.
Though these developments are great, we have to face the underlying problem of the entire porting versus emulation debate: What's fundamentally wrong with the question?
Made for Linux
Luckily, some gaming companies have realized the potential value of releasing Linux-native video games alongside their Windows and Macintosh counterparts. The Linux community is replete with frustrated gamers, most of whom, until recently, found themselves either giving up commercial games or dual-booting for the purpose of gaming. (Hey, you might as well make use of that Microsoft tax.) Lucky for them, a batch of new commercial games is now beginning to appear on the Linux platform.
The first of these notables was Id Software'sQuake III, which was the first title from a major video game company to be released simultaneously for both Windows and Linux. More recently, BioWare announced the upcoming release of its newest title, Neverwinter Nights, a Dungeons and Dragons role-playing game that is tentatively scheduled to be released on Windows, Macintosh, and Linux simultaneously. In fact, all three versions would come in the same box.
How Open Source fits into the picture
With all this going on, you might think that Open Source and commercial games don't mix. Not so, my penguin gaming friends. Not according to Sunspire Studios. With its newest title, Tux Racer, Sunspire has decided to use the Open Source model to take an Open-Sourced game commercial. With more than a million downloads, the game is already quite popular, but the question remains as to whether it will be a financially worthwhile endeavor. In Tux Racer, players race as one of four Arctic creatures through 18 downhill courses, all while gobbling up as many herring as possible. The (rather addictive) game is fun, simple to learn and is suitable for all ages.
As you can see, there are already a number of big (and not so big) players in the Linux gaming scene. The great thing is that all of the tools needed to create a 3D game are available in both forms of "free" (beer and speech). Even better is that there are already numerous projects out there that anyone interested in game programming can look at, learn from, and even help in developing. The trick is putting all the information together.
Writing Games: What you'll need
In order to begin writing your own 3D games under Linux, you need to acquire the necessary tools for the job. To a certain extent, the tools you use will be dependent upon the hardware you've got, so make sure that your hardware is supported by whatever software you decide to use. Everything that I talk about here was tested on my own humble, little system: a Pentium III 450mhz with 128mb RAM and 16mb ATI All-In-Wonder 128 video card running SuSE Linux 7.3. I'll presume that you have at least this much horse-power and that you're running a version of XFree86 4.x or greater. If you don't know what version you have running, whip out that handy-dandy virtual console and type the following command:
[gnorb@geex gnorb]$ XFree86 -version
You should get something like this:
XFree86 Version 4.1.0 / X Window System (protocol Version 11, revision 0, vendor release 6510) Release Date: 2 June 2001 If the server is older than 6-12 months, or if your card is newer than the above date, look for a newer version before reporting problems. (See http://www.XFree86.Org/FAQ) Build Operating System: SuSE Linux [ELF] SuSE Module Loader present
Most recent commercial distributions will come XFree86 4 or greater already installed, so you should be fine. If you're still in the 3.x series of XFree86, you might need to upgrade. You can check whether your video card is supported and get the latest release at the Xfree86.org Web site. You can also check there for installation information. Some distributions have easy-install packages (such as RPMs and DEBs), so make sure to check your distribution's Web site for details.
Once that's been straightened out, make sure that you can get 3D support under Linux for your video card. This normally means getting OpenGL (or an OpenGL alternative) up and running. If you've got a decent video card and are dealing with a major distro, then this shouldn't be of much concern. OpenGL, GLX (the glue that binds OpenGL to X) and the X server integration of GLX are Linux system components. They should be part of Debian, Red Hat, Mandrake, SuSE, and Caldera, as well as other distributions.
If you find that you don't have the necessary components, and you've got an ATI, Matrox, 3dfx, 3D Labs or Intel video card, then you should check out Precision Insight'sDRI project status page. XFree86 4 includes DRI GLX drivers for hardware-accelerated OpenGL, so it's now just a matter of making sure that everything is set up correctly.
*A note to you SuSE users out there, you might want to check out the command switch2xxx (example: switch2xf86_glx). If it looks like everything is set up the way it should be and it still doesn't work, this will probably help you fix it.
If you're using an NVIDIA card then you're pretty much on easy street. You can download pre-compiled drivers for their chipsets from its Web site. Unfortunately, they're closed source, so if you're not comfortable with the idea of having a closed source driver near your kernel, then there's not much you can do. The specifications of NVIDIA drivers are not openly available, so there's no way to make an Open-Sourced driver for their card.
By now you should have 3D up and running. To actually start the programming process, you're going to need a few libraries and tools. You can get the Linux Game Development Center'sList of packages containing (more or less) everything you need to code a game at http://lgdc.sunsite.dk/resources/category16.html. Remember, you need to understand concepts like 2D graphics and 3D-to-2D projection before you move on to things like 3D objects and complete interactive 3D worlds. If you don't yet understand these things, there are a number of books out there which can explain these concepts from top to bottom, my favorite being Norman Lin's Linux 3D Graphics Programming, published by Wordware Publishing.
What follows is a listing of some of the tools and concepts you'll need to familiarize yourself with in order to get up and running with 3D game programming under Linux, including where to get more information on the subjects.
Concepts to understand
Before you get started with functions and classes and objects (oh, my!), you have to first understand a few concepts regarding 2D and 3D graphics, at least if you want to do any serious work. You'll need to understand certain geometric and mathematical theories, like vectors, matrices, intersections, mappings and coordinate systems. To acquire this almost-forbidden knowledge, you should really try to find a good Linux 3D programming textbook, a list of which can be found at the end of this article.
In addition to 2D/3D theory, an understanding of the X Windowing System is necessary. You can get an overview of the protocol at http://www.x.org/about_x.htm. You'll need a bit of knowledge of hardware display technology and raster displays (a quick explanation of which you can find here). Once you understand this foundation, the rest is merely a matter of implementation.
Some of the basic tools
Earlier, I told you about OpenGL, something you are supposed to install on your system in order to be able to run 3D applications. OpenGL is developed by SGI and is an environment used to develop 2D and 3D graphics applications. Because of its popularity, it has become an industry standard API for cross-platform 3D and 2D application building. In fact, until recently, 3D games that were ported (or emulated) to Linux were exclusively built using OpenGL. TransGaming, however, has recently released for Linux Max Payne, a fully DirectX-based game.
Unfortunately, it's not all fun and games here. Some people don't like OpenGL due to its license, so they opt for the alternative, Mesa. Mesa, written by Brian Paul, is a free graphics library with an API almost identical to OpenGL. Programs using OpenGL can use Mesa without changing the source code, so whichever route you want to take is completely up to you and your hardware.
Alongside OpenGL/Mesa, you'll need a OpenGL/Mesa-based library to serve as a sort of glue between X and the API. That's where GLX, Utah-GLX, and GLUT come into play. GLX, as I said earlier, is the glue that connects OpenGL to the X Window System. It's required by any OpenGL implementation using X. A step beyond that is the Utah-GLX implementation, which offers a hardware accelerated GLX module for free Unix-type systems. The Utah-GLX project was born after SGI released GLX under a public source license. Utah-GLX has been included with the DRI release included in XFree86 4.x. The OpenGL Utility Toolkit (GLUT, pronounced as in glutton) is a free library written by Mark Kilgaard. It simplifies the implementation of frequently occurring
OpenGL operations, and because it's built on top of OpenGL, it's compatible with Mesa.
Another important component in video game development (or multimedia in general) is the Simple DirectMedia Layer (SDL). SDL is a library that provides fast access to the graphics framebuffer and audio device. SDL doesn't actually talk to the hardware, unlike many multimedia toolkits. It instead serves as a later between the application and the underlying system. This allows SDL-dependent applications to run unchanged in any environment that SDL runs in with nothing more than an simple recompile.
Still more tools
Most major Linux distributions include the components I have just covered. If you're just interested in playing games, then these tools will generally suffice. For those of you who want to know a bit more, here is a short list of Open-Sourced tools you might need to pick up along the way. Note that a number of these are alpha and beta versions, still in development or just beginning to be developed.
ClanLib is a gaming library released under the GNU General Public License that offers 2D and 3D graphics, image, sound and networking routines. The project's goal is "to allow the game developer to focus on stuff that matters, avoiding all those nasty (and boring) low level travails like setting up a directdraw window, sound mixing, reading image files, etc." ClanLib is currently at version 0.5.4 (released January 22, 2002).
PLIB is a suite of portable game libraries developed by Steve Baker (co-creator of the obscenely addictive TuxKart). The project, released under the GNU Lesser General Public License (LGPL), aims to create a set of tools that allows programmers to write games and other interactive applications that are portable across a wide range of operating systems. In fact, PLIB has been used, under a modified license, to create games for Sony's PlayStation line of consoles. The PLIB suite of libraries includes sound effects, music, a complete 3D engine, font rendering, a GUI, networking, 3D math library and a collection of handy utility functions and is currently is version 1.4.2 (stable).
3D applications, games and engines
Crystal Space is a free, portal-based portable 3D game development kit licensed under the LGPL. It supports "true six degrees of freedom [6DOF], colored lighting, mipmapping, portals, mirrors, alpha transparency, reflective surfaces, 3D sprites ... 32-bit display support, Direct3D, OpenGL, Glide ..." You can see the full list on its features page. There are currently about 600 people working on Crystal Space, so it's a fairly active project, the latest stable release being 0.94.
Descent is a commercial, portal-based 3D game that has been Open Sourced and ported to Linux.
FlightGear is an Open Source, multi-platform, cooperative flight simulator development project. The goal of the project "is to create a sophisticated flight simulator framework for use in research or academic environment, for the development and pursuit of other interesting flight simulator ideas, and as an end-user application." That aside, it's a heck of a lot of fun, if you like flight sims. The project is currently at version 0.7.9.
Tuxedo T. Penguin: A Quest for Herring
Developed by PLIB creator, Steve and his son Oliver Baker, the Tux_AQFH project is aimed at creating a friendly search-and-explore and puzzle game with an emphasis on game-play and fun, as opposed to graphical quality (though it looks quite good). It's similar to some console games like Mario '64 and Banjo-Kazoole. The project is currently a small project, but it is a great project for anyone new to the field of game programming to sharpen their skills. From the project goals: "I'd particularly like to end up with a setup where individuals can design levels and contribute them to the game so that we all wind up with endless numbers of new levels to play and enjoy."
This game is also developed by the father/son team of Steve and Oliver Baker. Like Tux_AQFH, TuxKart is a family friendly, extremely addicting and fun game. The project is always looking for more collaborators, so if you're looking to sink your teeth into a fun side project, then this is what you're looking for. Artist, programmers, musicians and level designers are welcome to come and help.
Originally developed as a commercial product, World Foundry enables non-programmers to create 3D environments and games. It is a complete 3D game production environment with advanced physics, camera and scripting systems, capable of varied behavior without changing the engine itself. It has been used to create games for Windows and Sony PlayStation and is now being ported to Linux.
3dom (3D Object Modeler) is a modeler licensed under the GPL. It was designed to be renderer independent.
AC3D is a 3D object/scene modeler available for various platforms (Linux, Windows 95/98/NT, Solaris, SGI, and HPUX). It's shareware and only comes in binary format.
Blender is a freely available, professional 3D modeler which has been used to create 3D graphics in commercial production environments. Though it has a steep learning curve, once learned, Blender becomes a very flexible, powerful, and quick tool to work with. Unfortunately, its parent company, Not a Number (NaN) recently filed for bankruptcy (which is why I didn't link to the original hope page at http://www.blender.nl). Luckily, the program is still available from other sources, such as BlenderMind. If you already have Blender and wish to convert your files to another modeler, you can check out AC3D's python conversion scripts, which will allow Blender to export and import aC3D model files.
Midnight Modeler is a CAD-like modeler written for DOS by David R. Taylor, later ported to Linux by Michael Lamertz. It has a command line- and menu-based interface and it has tools to generate and deform meshes.
Pretty Poly Editor
Pretty Poly Editor is a portable Open Source 3D modeler, file viewer and converter.
Currently, it is in alpha release, so it's not very useful yet as a modeler; however, it currently serves as a good 3D file converter.
Sced is a constraint-based scene editor program that makes use of geometric "constrains" to edit objects in a virtual world. It is currently version 1.03.
*Note: you can check out a full list of modelers available for Linux at http://www.computer.privateweb.at/tech-edv/MODlinks.htm.
The Open Audio Library (OpenAL) is "an effort to create an open, vendor-neutral, cross-platform API for interactive, primarily spatialized audio." The initiative, licensed under the LGPL, was originally started by Loki to compensate for spatialized sound above and beyond left-right panning in the Windows versions of Heretic 2 and
Heavy Gear 2. It has since been used by Loki in its ports of Soldier of Fortune, SimCity 3000 Unlimited, Mindrover, and other games. Creative later developed an interest in the project and announced the initiative along with Loki during the Game Developer's Conference (GDC) in March 2000 (though Creative had expressed interest in OpenAL before then in order to complement its own driver work). OpenAL now supports a number of stereo and multi-channel formats, some of which are quite proprietary.
For more information...
Now that you have a good bird's eye view of what's involved in with programming 3D games on Linux, it's time to really dig into the subject. There are a number of resources on the Internet to assist you as you delve more deeply into the subject matter. A couple of sites to note are the Linux Game Development Center and the Linux 3D Graphics Programming information site. Both of these will contain a large amount of information, tutorials, and links regarding this subject. Personally speaking, I prefer a good book to online documentation (all other things being equal). As such, here is a list of books which might be helpful to you in case you decide to stop by your local bookstore (and if you live in Tampa, you just might see me wandering about).
- Linux Game Programming by Mark "Nurgle" Collins, published by Premier Press
- Programming Linux Games by John R. Hall, published by No Starch Press
- Linux 3D Graphics Programming by Norman Lin, published by Wordware Publishing
- Advanced Linux 3D Graphics Programming by Norman Lin, published by Wordware Publishing