3. Libraries

We'll run through the different gaming libraries you'll see under Linux.

3.1. What is Glide2?

Glide2 is an low level graphics API plus driver that accesses 3D hardware accelerated functions on 3dfx's Voodoo I, II and III cards, under XFree86 3.*.

A program can ONLY use the special hardware accelerated features of these cards by using the Glide2 library in one of two ways:

3dfx opened up the specifications and source code to the open source community. This allowed Daryll Strauss to port Glide2 to Linux which enabled XFree86 3.* users to use Voodoo I, II and III cards under Linux.

Since Glide2 accesses the video board directly, applications that use Glide2 will either need to be run by root. A way around this was to create the kernel 3dfx module. This module (and the corresponding device /dev/3dfx) allows Glide2 hardware acceleration for non-root users of non-setuid graphics applications.

Unfortunately, Glide2 is also a dead issue. It's only used for Voodoo I, II, III boards (which are becoming outdated), under XFree86 3.* (most people use XFree86 4.*). And since 3dfx is now a defunct company, it's a sure bet that no more work will be done on Glide2 and no more games will be written using Glide2.

3.2. What is Glide3?

Glide3 is not a direct API used to program a game with, unlike Glide2. It exists only to support DRI on Voodoo III, IV and V boards under XFree86 4.*. None of the games which use Glide2 will work with Glide3. This shouldn't be a surprise since Glide2 and Glide 3 support different video boards and different versions of XFree86. The only video card that can use both Glide2 (under XFree86 3.*) and Glide3 (under XFree86 4.*) is the Voodoo III. It's reported that a Voodoo III using Glide2 will outperform a Voodoo III using Glide3.

When you use a Voodoo III, IV or V under XFree86 4.*, you want to use a version of Mesa (see Section 3.4) which was compiled to use Glide3 as a backend to ensure hardware accelerated OpenGL on your system.

3.3. What is OpenGL?

OpenGL is a high level graphics programming API originally developed by SGI, and it became an industry standard for 2D and 3D graphics programming. It is defined and maintained by the Architectural Revision Board (ARB), an organization whose include SGI, IBM, DEC, and Microsoft. OpenGL provides a powerful, complete and generic feature set for 2D and 3D graphics operations.

There are 3 canonical parts to OpenGL:

OpenGL is not only an API, it's also an implementation, written by SGI. The implementation tries to use hardware acceleration for various graphics operations whenever available, which depends on what videocard you have in you computer. If hardware acceleration is not possible for a specific task, OpenGL falls back on software rendering. This means that when you get OpenGL from SGI, if you want any kind of hardware acceleration at all, it must be OpenGL written and compiled specifically for some graphics card. Otherwise, all you'll get is software rendering. The same thing is true for OpenGL clones, like Mesa.

OpenGL is the open source equivalent to Direct3D (a component of DirectX). The important difference being that since OpenGL is open (and DirectX is closed), games written in OpenGL are much easier to port to Linux while games written using DirectX at this point in time are impossible to port to Linux.

3.4. What is Mesa?

Mesa is a free implementation of the OpenGL API, designed and written by Brian Paul. While it's not officially certified (that would take more money than an open source project has), it's an almost fully compliant OpenGL implementation conforming to the ARB specifications. It's reported that Mesa is even faster than SGI's own OpenGL implementation.

Just like OpenGL, Mesa makes use of hardware acceleration whenever possible. When a particular graphics task isn't able to be hardware accelerated by the video card, it's software rendered; the task is done by your computer's CPU instead. This means that there are different builds of Mesa depending on what kind of video card you have. Each build uses a different library as a backend renderer. For example, if you have a Voodoo I, II or III card under XFree86 3.*, you'd use mesa+glide2 (written by David Bucciarelli) which is the Mesa implementation of OpenGL that uses Glide2 as a backend to render for graphical operations.

3.5. What is DRI?

Graphics rendering has 3 players: the client application (like Quake 3), the X server and the hardware (the graphics card). Previously, client applications were prohibited from writing directly to hardware, and there was a good reason for this. A program that is allowed to directly write to hardware can crash the system in any number of ways. Rather than trusting programmers to write totally bug free, cooperative programs that access hardware, Linux simply disallowed it. However, that changed with X 4.* with Direct Rendering Infrastructure (DRI). The direct rendering infrastructure allows X clients to write 3D rendering information directly to the video card in a safe and cooperative manner.

DRI gets the X server out of the way so the 3D driver (Mesa or OpenGL) can talk directly to the hardware. This speeds things up. The 3D rendering information doesn't even have to be hardware accelerated. On a technical note, this has a number of virtues.

3.6. What is GLX?

GLX is the X extension used by OpenGL programs, it is the glue between the platform independent OpenGL and platform dependent X.

3.7. What is Utah GLX?

Utah-GLX is the precursor to DRI. It makes some different design decisions, regarding separation of data and methods of accessing the video card. (For instance, it relies on root privileges rather than creating the kernel infrastructure necessary for secure access). It provides support for (at this time) a couple cards which are not well-supported in DRI. Particularly, the ATI Rage Pro family, S3 Virge (although anyone using this for gaming is, well, nuts), and an open source TNT/TNT2 driver (which is very incomplete). The TNT/TNT2 driver is based on reverse-engineering of the obfuscated source code release of the X 3.3 drivers by nVidia. However, they're really incomplete, and effectively, unusable.

As a side note, until the G400 stuff is *really* fixed in DRI, it's also the better G400 support—but hopefully that will not be an issue by the time this HOWTO is published.

3.8. What is xlib?

Every once in awhile you'll see some sicko (said with respect) write a game in xlib. It is a set of C libraries which comprise the lowest level programming interface for XFree86. Any graphics programming in X ultimately makes use of the xlib library.

It's not an understatement to say that xlib is arcane and complicated. A program that simply connects to an X server, puts up a window and does nothing else could be a complicated 40 line program with arcane and very long named functions. Because of this, there are lots of libraries which hide the details of xlib programming. Some of these libraries focus on drawing in windows (like SDL). Other libraries are more concerned with widgets within windows (eg pulldown menus, radio buttons and text boxes); these types of libraries are called widget sets. Gtk is the canonical widget set on Linux, but there are many others like fltk (a small C++ widget set), Xaw, Qt (the widget set of KDE), and Motif (the widget set used by Netscape). Motif used to be king of the Unix world, but was very expensive to license. The Open Group opened up Motif's license for non-commercial use, but it was too little too late. People now use Lesstif, a Motif clone.

3.9. What is SDL?

SDL (Simple DirectMedia Layer) is a library by Loki Software's Sam Lantiga (graduate of UCD, yeah!). It's actually a meta-library, meaning that not only is it a graphics library which hides the details of xlib programming, it provides an easy interface for sound, music and event handling. It's LGPL'd and provides joystick and OpenGL support as well. The 40 line arcane program I mentioned in the xlib section can easily be written in 6 lines of straightforward code using SDL.

The most striking part of SDL is that it's a cross platform library. Except for a few details about header files and compiling, a program written in SDL will compile under Linux, MS Windows, BeOS, MacOS, MacOS X, Solaris, IRIX, FreeBSD, QNX and OSF. There are SDL extentions written by various people to do things like handle any graphics format you care to mention, play mpegs, display truetype fonts, sprite handling and just about everything under the sun. SDL is an example of what all graphics libraries should strive for.

Sam had an ulterior motive for writing such a cool library. He's was the lead programmer for Loki Software, which used SDL in all of its games except for Quake3.

3.10. What is GGI?

GGI is seemingly now-defunct project which aimed to implement the graphics abstraction layer in lower level code, putting graphics hardware support in one place, bringing higher stability and portability to graphics applications and replacing SVGAlib, fb, and X servers dealing directly with hardware.

GGI was supposed to have a kernel module inserted into the Linux source code but Linus thought their code wasn't ready for production kernels. There was brief talk about making *BSD their main platform. It's been ages since I've heard anything about GGI.

3.11. What is SVGAlib? Frame buffer? Console?

The console is the dark non-graphical screen you look at when your computer first boots up (and you don't have have xdm or gdm running). This is opposed to the X environment which has all sorts of GUI things like xterms. It's a common misconception that X means graphics and console means no graphics. There are certainly graphics on the console—we will discuss the two most common ways to achieve this.

SVGAlib is a graphics library that lets you draw graphics on the the console. There are many graphical applications and games that use SVGAlib like zgv (a console graphical image viewer), prboom and hhexen. I happen to be a fan of this library and of graphical console games in general; they are extremely fast, fullscreen and compelling. There are three downsides to SVGAlib. First, SVGAlib executables need to be run by root or be setuid root, however, the library releases root status immediately after the executable begins to run. Secondly, SVGAlib is video card dependent–if your video card isn't supported by SVGAlib, you're out of luck. Third, SVGAlib is Linux only. Games written in SVGAlib will only work on Linux.

Frame buffers are consoles implemented by a graphics mode rather than a BIOS text mode. Why would you want to simulate text mode from a graphical environment? This allows us to run graphical things in console, like allowing us to choose what font we want the console to display (which is normally determined by BIOS). Imagine having a console font of Comic Sans MS? There's a good Frame Buffer howto available from LDP.

3.12. What is OpenAL?

OpenAL aims to be for sound what OpenGL is for graphics. Jointly developed by Loki Software and Creative Labs, it sets out to be a vendor neutral and cross platform API for audio. It is licensed LGPL and the specs can be had for free from the OpenAL website. OpenAL is fully functional, but now that Loki Software is no more its future development is questionable.