Originally Published: Monday, 20 December 1999 Author: Jorrit Tyberghein
Published to: featured_articles/Featured Articles Page: 1/1 - [Printable]

Crystal Space: An Open Source 3D Engine

One of the most heard criticism on Linux is the lack of support for games. There still seem to be many people that think that Linux is a boring operating system with a command line interface and a few text-based games like hangman or NetHack. Of course, there's nothing wrong with those games -- NetHack is a very good game and is probably my all-time favorite....

   Page 1 of 1  

One of the most heard criticism on Linux is the lack of support for games. There still seem to be many people that think that Linux is a boring operating system with a command line interface and a few text-based games like hangman or NetHack. Of course, there's nothing wrong with those games -- NetHack is a very good game and is probably my all-time favorite.

I think there is nothing wrong with Linux that would prevent it from being an excellent game platform. But we need to break this circle of ignorance! Because people think Linux is not suitable, game developers will not program for it. And that only make the idea that Linux is not suitable stronger. Luckily there are a few companies which are very actively trying to break the circle. For example, Id Software, with Quake and its successors, and Loki Entertainment Software, have recently put a great deal of attention on the Linux gaming potential.

There are also several Open Source game development kits in various stages of completion. Some are for 2D graphics. Some have support for sound. I'd like to tell you about a possible 3D solution for Linux games: Crystal Space.


First let me tell you a bit about the history of Crystal Space. Some time ago when I was playing games like Doom, and later Quake, I remember myself thinking: "How the hell (pun intended) do they do that?." It was a constant source of frustration for me that I didn't know how they managed to get such nice visuals on a simple 486 computer. I thought this was something restricted for high end stations like Silicon Graphics.

So I started scanning the Web for information. For six months, I browsed the Web, bookmarking and saving every tidbit of information that I could find. At some point there was a message on the comp.graphics.algorithms newsgroup that mentioned something about portals. This was the first time that I encountered that term. The message did not explain much but this was the spark that I needed! At that time I was a little scared of all that 3D math and the BSP tree was another such thing that scared me. But portals seemed so easy.

At once I started coding (this is around the end of June in 1997). In two months I got a basic portal 3D engine running with six degrees of freedom, mipmapping, colored lighting, moving objects, primitive scripting and some other stuff. My research had paid off: Crystal Space was born.

But then I got a little problem: I ran out of free time. Rather than let the code rot away on my hard disk I decided to release it to the public. The first release was simply a message on some of the newsgroups. People could get the source by mailing me. I mailed them the source back. The Crystal Space community was born. This started a long period of Crystal Space growth by mail. People sent me contributed code, I integrated it into CS, and mailed the result back.

Later on I got an FTP site on Geocities which helped a lot. Later still I moved to www.linuxgames.com for more space and speed. But the greatest boon to CS development has been the CVS server which we have had for some time. That server means that I don't have to worry about integrating all contributions. The development cycle of CS has been speed up enormously since then.

Eventually I got rid of my scare for BSP trees and other more advanced 3D stuff (octrees, c-buffer, and so on). So Crystal Space became more mature.

But What Is Crystal Space?

Good question. Crystal Space started as a 3D engine only. But recently it has grown into a real 3D Game Development Kit. The core of the kit is the 3D engine. In addition you get components for (3D) sound, networking, physics, and so on. You get a number of libraries and components which you can use in your games (or other applications; I like to think that CS should not be limited to games). You don't have to use them all. If you want you can use the 3D engine but not anything else. Or you could use the sound support only. This is possible because we put a lot of work into a flexible plug-in system. 3D drivers (such as OpenGL, Glide, Direct3D, or software renderer) are separate modules that are loaded by Crystal Space when needed. The same is true for sound and networking.

There are also low-level libraries in Crystal Space that can also be used separately in other applications. There is a geometry library (containing support for matrices and vectors), a utility library (with support for reading ZIP archives and such), and so on. All those components and libraries are Open Source and under the LGPL license (GNU Lesser General Public License).

Crystal Space was initially developed on Linux and that is still its main development platform. But a lot of people have contributed ports for several systems. Crystal Space now compiles and runs on Windows, DOS, OS/2, BeOS, Macintosh, NextStep, OpenStep, FreeBSD, SGI, Solaris, etc. This portability is achieved without a single line of OS specific code in the libraries themselves. All system-dependent code is put in a separate library.

The 3D Engine

Let's now focus a bit on the 3D engine itself, which is still the main reason to use Crystal Space. The engine started as a pure portal engine. You have small convex sectors which are connected through portals. In addition you can enhance sectors by adding 'Things'. By using these building blocks you can build nice levels already. But portals have one problem (at least one problem). They are mainly suitable for indoor-style levels. It is not easy to represent an outdoor level with portals and sectors and doing so would create levels that are not efficient at all because of the high number of portals.

So recently there are a number of new features that try to eliminate this indoor limitation. First, there is now a landscape engine based on the ROAM algorithm. Using this landscape engine it is now possible to use Crystal Space for flight simulators or other games requiring outdoor levels. The landscape engine is a recent addition and we are still working on it. But it will be possible to fully integrate landscape levels and indoor portal levels. So you will be able to add buildings on the landscape and go inside to the normal portal engine. This integration is seamless; the user will not notice that another engine is at work there.

In addition we are also working hard on techniques to make displaying complex polygon meshes more efficient without having to resort to portals. One technique we use there is to put a sector in an octree. This is a big hierarchical structure which helps greatly to structure extremely large levels (200 000 polygons or more!). Combine this with the c-buffer (for software rendering) or the coverage mask tree algorithm.

So Crystal Space is still growing. One major area we're are working on right now is support for hardware accelerated Transform and Lighting (abbreviated T&L). The nVidia GeForce256 supports this kind of acceleration but we needs some work in the engine to be able to use it.

A lot of attention is also put in support for 3D triangle mesh actors (called 3D sprites in Crystal Space). These are important for modeling adversaries and actors in a game. The CS engine already has considerable support for skeletal animation, frame based animation with interpolation, progressive mesh LOD (Level Of Detail), and so on. But we will be working in this area a lot too.


Another important area for many games is scripting. Crystal Space offers several solutions for this problem. The built-in scripting system is a bit obsolete and we're going to remove that soon, but using the powerful plug-in system, you can now use Crystal Space in combination with any language that you would want. Currently we provide support for integration with the Python language. Scripting with C++ or C is of course also possible. Check out the Crystal Script project for more information about this.

Game Libraries

Crystal Space itself is a 3D engine library (and some other components). As such it is not restricted to gaming so you will not find game-specific features in the 3D engine. There are a number of other libraries that provide you with more game-specific features.

First there is the physics library which is separate from the rest of Crystal Space but which integrates fully with it. Then you have the csgame library. This library is meant mostly for FPS type games and provides a bunch of ready solutions for those types of games on top of the Crystal Space framework.

Lastly there is the Crystal Clear project. The purpose of this project is to develop a 3D gaming system based on the Crystal Space 3D Engine and free software. Their goal is to develop a modular gaming system which is flexible enough to support different genres of 3D games. This can be accomplished by defining a set of interfaces with which the various modules communicate. The modules can be rewritten as the game requires.

The advantage of this approach is that game developers of completely different style games can share code and shorten development time. With LGPL'ed modules, even commercial projects could benefit from this project while giving back to the free software community. The possibilities are endless! (The last few sentences have been copied shamelessly from the Crystal Clear home page :-) ).

The physics, csgame, and Crystal Clear libraries are all included with the basic Crystal Space distribution. You can choose!

Getting More Information

The best source for more information about Crystal Space is the Crystal Space home page at http://crystal.linuxgames.com/. In addition you can always mail me with questions or such. Crystal Space is an Open Source project. A lot of people are already helping me but I always need more people! Feel free to have a look at the site so that you can decide if CS is something for you, either to use in your own project or to help development.

I hope to hear from all of you soon!

Jorrit Tyberghein, Jorrit.Tyberghein@uz.kuleuven.ac.be.

   Page 1 of 1