Originally Published: Monday, 20 November 2000 Author: Jorrit Tyberghein
Published to: develop_articles/Development Articles Page: 1/1 - [Printable]

Crystal Space: An Open Source 3D Engine

What does it take for Linux to become a great game development platform? Having development kits certainly wouldn't hurt! In this feature, Jorrit Tyberghein discusses the features of Crystal Space, the 3D engine and game development kit he started.

   Page 1 of 1  

One of the most widely heard criticisms of Linux is the lack of support for games. There still seems to be many people who think that Linux is a boring operating system with a command line interface and a few text-based games such as hangman or NetHack. Of course, there's nothing wrong with those games; in fact, 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 reinforces the idea that Linux is not suitable. 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 to the potential of Linux gaming.

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.

History

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 workstations 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 features. 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 the code base, and mailed the result back.

Later on I got an FTP site on Geocities which helped considerably. Later still I moved to www.linuxgames.com for more space and speed. But the greatest boon to Crystal Space 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 Crystal Space has sped 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 Crystal Space 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 remains 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, and so on. 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 there are a number of features that try to eliminate this indoor limitation to make Crystal Space usable for many types of 3D games. First, there is a landscape engine from the DDG toolkit. Using this engine it is now possible to use Crystal Space for flight simulators or other games requiring outdoor levels. Crystal Space allows you to fully integrate a landscape with buildings using the normal portal engine. So you can go inside a building and then you are back in the normal portal engine algorithm. This is all seamless; in other words, the player doesn't notice any transition.

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. In the future we will also work more on better support for hardware accelerated Transform and Lighting (abbreviated T&L) like the nVidia GeForce chip supports. We already support this for terrains, curved bezier surfaces and 3D actors but more support would be useful.

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 Crystal Space 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.

Scripting

Another important area for many games is scripting. Crystal Space offers a very general solution for this problem. Basically we expose a public API that can be used by any scripting engine. So you can even write scripts in plain C++. However, we have additional support for scripting through Python. One of the best examples of how this can work is the Dreams Eternal project which is an FPS game that is using Crystal Space and Python. The work we did on Python scripting can very easily be used for Java too but we haven't done this yet. We are using SWIG as a general wrapper between C++ and a scripting language.

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 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 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!

Window System

In addition to all this there is also a window system built into Crystal Space. This WM runs inside a window on the host operating system, so it supports the same look-and-feel on all platforms we support (even DOS!). The window system is also integrated very well with the 3D engine. Many games using Crystal Space are now using both the engine and the window system. Again you can check Dreams Eternal for an example of this.

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