Originally Published: Tuesday, 26 June 2001 Author: John Hall and Loki Software
Published to: develop_articles/Development Articles Page: 3/6 - [Printable]

Linux Gaming APIs: Chapter 3 of PROGRAMMING LINUX GAMES

Today's Linux.com article, derived from Chapter 3 of the book Programming Linux Games by John Hall, takes a look at the various Linux gaming APIs you can use to construct your game. Don't reinvent the wheel, and don't compromise your open source roots, and check out this excerpt from No Starch Press.

Graphical User Interface Toolkits  << Page 3 of 6  >>

Graphical User Interface Toolkits

Many games use menus and dialogs to let the user make configurations changes and select the type of game to play. In many cases it's practical to build an ad hoc interface for a particular project, but games with complex settings might benefit from a more substantial user interface toolkit. There are plenty of good GUI packages to choose from.


Originally developed to serve as the GNU Image Manipulation Program's user interface, GTK+ (formerly just GTK) is an enormous GUI library that somewhat resembles the time-tested Motif toolkit. GTK+ is implemented on top of an abstraction layer called GDK, freeing GTK+ from low-level concerns like input gathering and pixel format conversion.

GTK+ is implemented in pure C, but C++ wrapper libraries are available. Its programming model takes a bit of getting used to, but it is powerful enough for building interfaces for large applications. It would be a major hassle to port GDK/GTK+ to work with anything but the X Window System or Microsoft Windows, so you can pretty much forget about using it to develop games for the framebuffer console.

The GTK+ project is online at http://www.gtk.org.


The Tk toolkit was originally created as a windowing interface for the Tcl scripting language, but it's since found its way into a number of other environments. It is an extensible and flexible GUI toolkit for X11, Windows, and MacOS. Tk is tied to Tcl, but you can still develop your application in C and only use Tcl to build the interface. (If you don't mind a bit of extra work, you can bypass Tcl entirely, but Tk wasn't really designed for this.) Tk is available under the same (extremely liberal) license as Tcl, and it can be modified and used in any type of application with very few restrictions. More information is available on http://www.tcltk.org.


Fltk stands for "fast, light toolkit". It is a very small C++ GUI toolkit that works on several different platforms (and is easily portable to others). Fltk requires very little of the underlying platform, and this makes it a good candidate for integrating into existing graphics systems (games, for instance). This toolkit is released under the GNU LGPL, and more information is available from http://www.fltk.org.


Qt is a comprehensive, portable application development system for C++. It shares some similarities with Microsoft's MFC toolkit, but it's refreshingly different in implementation. Qt is portable between Unix and Windows, and there is even an embeddable version of Qt for handheld devices. It's really not fair to call Qt a GUI toolkit; it does serve that purpose, but it also provides basic data structures, file I/O, networking, image loading and saving.

TrollTech (a free software-friendly Norwegian company) created and maintains Qt as a commercial product, and you need to buy a license if you intend to use Qt in proprietary software. The Linux version is available under both the GNU General Public License and the custom Q Public License, but these require all unlicensed Qt applications to be free. Qt is great for creating free software and for serious commercial development, but it's probably not what you want if you're interested in small-scale, non-free development.

More information on Qt is available at http://www.trolltech.com.

SDL GUI support

There's no "official" SDL GUI toolkit, but there are a few user-contributed libraries that fill this niche. The SDL GUI library provides basic things like frames, menus, and widgets, while the SDL console library implements a Quake-like popup console system. Both of these libraries are free software, and you can hack them to your liking (provided, of course, that you contribute your modifications back to the community at large).

These and other user-contributed SDL add-ons are available on http://www.libsdl.org.

Graphical User Interface Toolkits  << Page 3 of 6  >>