Linux DevCenter    
 Published on Linux DevCenter (http://www.linuxdevcenter.com/)
 See this if you're having trouble printing code examples


Crystal Space: 3D for Free

by Howard Wen
05/16/2000

If you want to create your own 3D graphics game, you need to have a 3D graphics engine to build it on. Traditionally, your choices were limited to either programming your own graphics engine from scratch or paying a licensing fee to use another company's -- a price which typically starts out at around $100,000. But if you don't have the programming skill or money to burn, there has been a third, though relatively unknown, alternative for a while now: Crystal Space, an open-source 3D graphics engine that was created by 30-year-old Belgian programmer Jorrit Tyberghein.

Three years ago, Tyberghein wrote the first version of Crystal Space after seeing first-person shooter games like Doom and Quake and wondering how 3D graphic games like these were made. With no prior experience in graphics programming, he started by looking for information on the Internet about 3D graphics programming. Based on his personal research, he put together the first version of Crystal Space in a little over two months.

But then he had to stop developing the engine because of increasing responsibilities at his job that were taking up more of his time. "I could have let the code sit on my hard disk to rot away into oblivion," Tyberghein says. "Or, I could release it for free. I did the latter. I sent a message to some newsgroups. People could e-mail me and I would e-mail them a copy of the source."

That's how the Crystal Space community was born. Soon after Tyberghein gave away the source to Crystal Space, volunteer programmers ported the original Windows code to other platforms like DOS, Macintosh and Amiga. Interestingly, when he released Crystal Space's code to the public back then, Tyberghein wasn't aware of the term "open source" and what it meant. "I released those initial versions of Crystal Space without any license at all because I was simply not aware of the need," he says. "Now of course, I can see that Crystal Space fits very well with the open-source movement."

Yet how important is a 3D graphics software engine these days (whether it be commercial or open source), with all the advanced and powerful 3D graphics cards that are increasingly becoming standard hardware features in computers? The answer is that even with the best 3D hardware, you still need a software engine to control that hardware. There is still much to do on the engine side, such as collision detection, artificial intelligence, and simply bringing gaming elements together within a logical, coherent package.

"Even with very fast hardware, there always is a limit to what that hardware can do," Tyberghein explains. "Game demands get higher and higher. So the engine still has to do some optimization to try to limit what is sent to the hardware. Even the best hardware cannot handle millions or more polygons just by rendering them all. The engine tries to find ways to quickly determine which parts of the game's world environment are not visible and which are visible."

The games Crystal Space can play

While Crystal Space is ideal for developing first-person games, because the engine's "camera" management is independent of the engine itself, it's equally well suited for making third-person perspective games -- something along the lines of Tomb Raider. Crystal Space is suitable for racing games and flight simulators as well, although the engine's landscape rendering needs to be improved in order to make such games comparable to a commercial product, Tyberghein admits.

A number of games are currently being made with Crystal Space. Most of these are role-playing games which are being developed by volunteers under an open-source format: TimeCity, The Amateur Scrolls, and Squawk. There's also an open-source first-person shooter, Crystal Shooter, and one commercial game, 3D Ultra Minigolf (published by Sierra On-Line), that was built on an earlier version of Crystal Space. Tyberghein theorizes that many of the games being developed with Crystal Space are role-playing because the engine includes full control of one or more "camera" perspectives and initial built-in support for networking. Both of these features make it easier to develop multi-player games such as role-players.

As for how Crystal Space compares to commercial 3D graphics engines, specifically those that power Quake 3 Arena and Unreal Tournament, Tyberghein confidently says his engine is comparable in terms of visual features but not in regard to code readiness. "Crystal Space is not finished. It is working very well already, but we still have a lot to do," he says. "I'm investigating the possibility of releasing a subset of Crystal Space that would most likely be the indoor renderer." He hopes that this subset, which generates 3D graphics similar to a commercial first-person shooter graphics engine like Quake's, can be finished and released within six months.

"In general, I think CS is much richer in features since it's not just an engine, it's a cross-platform game API," says Andrew Zabolotny, a 27-year-old programmer from St. Petersburg, Russia, who has been contributing his skills to Crystal Space's high-level coding. "It provides functions for almost anything you could need in any game. For example, it has a terrain-rendering engine. We have lots of things Quake or Unreal will never need because a first-person shooter is a very specific type of game which needs just a limited set of features."

In practical 3D game development terms, however, Thomas Hieber, who is developing Crystal Shooter, concedes that "Quake 3 is awesome. This is probably the most fantastic 3D engine currently around. Crystal Space is miles away from Quake 3 Arena in my honest opinion." But the 29-year-old software engineer from Germany doesn't think that this should stop anybody from creating great games with Crystal Space. "Take a look at Tomb Raider or Half-Life. Neither has a really great 3D engine," he says, "but they have all been successful, because of the value of their game play."

The good and the bad of Crystal Space

Overall, the Crystal Space 3D graphics engine was designed to be all-purpose enough to create almost any kind of game. Although it cannot be compared with other graphics programming platforms like OpenGL or Direct3D in terms of features, it has its own advantages over them. It is cross-platform, for one, so you can write code that will run equally well on Unix, Windows, OS/2, DOS, MacOS, and BeOS. A lot of thought was put into the platform independence of Crystal Space. The engine has a flexible plug-in system so that a single executable works with various renderers like OpenGL, Direct3D, and Glide. Along with the 3D API, it even has a 2D API, although, of course, the primary purpose of the engine is to produce 3D graphics. "I wrote a full-blown windowing GUI based entirely on the Crystal Space low-level API," says Zabolotny.

Crystal Space offers lots of features that are very useful if you want to create your own game under it, but its use is not limited just to game design. There are useful pieces of separate code that can be used outside of the engine in projects unrelated to gaming development: a csIniFile class (for .ini file management), an SCF (Shared Class Facility) subsystem, a csArchive class (which deals with .zip files), and a VFS (Virtual File System) subsystem.

Besides its cross-platform nature and code modularity, developers who have been working on Crystal Space in their free time cite the engine's stability (it rarely crashes), the completeness of its 3D rendering features, and a very active community of developers working on the code as other appealing reasons for working on and contributing to it.

The most significant weaknesses of Crystal Space are its lack of good collision-detection programming and its unstable API, since there are often lots of changes made to it and the source tree structure.

"In my opinion, the largest weakness for Crystal Space is its collision detection," says Hieber, who has been spending most of his time improving Crystal Space's capabilities first before working on his game, Crystal Shooter. "There is some support in it, but it is not very useful for real games. There is only static testing of object-against-object that will basically return information about where the collision occurs, if any. But there is no good support for fast moving objects."

Another complicated issue in Crystal Space is how it handles lighting. The engine supports colored static and dynamic lighting with soft shadows, but getting these to work fast under all possible game processing circumstances is a challenge, and one which CS currently doesn't completely meet, Tyberghein admits. The new PVS (Potentially Visible Set) will help address this problem, too.

What's in store for Crystal Space and what's needed

As with most open-source projects, Crystal Space definitely wants and needs more programmers to contribute to its cause. At the moment Tyberghein himself is looking for people who are very skilled at programming graphic engine internals and can also think in terms of algorithms -- people who can essentially help out with perfecting the engine itself. "It is still very fundamental work that is happening in the engine," he says. "I have lots of people helping on the other parts of Crystal Space (i.e., OpenGL and Direct3D programming, Windows and Linux porting) but very few people are capable of helping me with the engine."

"In general, if we had more good programmers, we could do much more," Zabolotny says. "We primarily need people skilled in cross-platform C/C++ programming."

Porting the Crystal Space engine to a gaming console such as the Sony PlayStation is being considered right now. There are some issues, though. A major technical one is that memory on gaming consoles is generally limited, and Crystal Space is rather memory hungry. So the Crystal Space development team plans to address this.

The other issue is a legal one: For some of these gaming consoles, a developer must sign an NDA (non-disclosure agreement) to be able to use the software developer's kit. "To overcome this problem, we are considering putting all NDA stuff in a separate library and then letting Crystal Space use that library," Tyberghein says. "This of course limits the use of Crystal Space in an open-source way on those platforms, but at least someone would be able to write that library again and then use the engine unmodified."

So could Crystal Space, or any open-source 3D graphics engine, become as widely used as the commercial engines? Tyberghein expresses some doubts. "If you license the Quake 3 engine, then you're sure to get a quality product that will work regardless. So if you want technical support, you should NOT use a free engine," he says. "However, if you feel like you can cope with the lack of support or if funding is a problem (which is the case for many people), then an open-source engine is for you."

As for any particular type of games Tyberghein would personally like to see others develop under Crystal Space, he thinks there are enough people developing games right now for the engine. What he would like to see more are non-game-related applications. "The Crystal Space engine is not game specific. There is nothing inside the engine that says, 'This is only useful for games,'" he insists. "Other uses for Crystal Space could be architectural, for example, or maybe for a garden designer program. There are lots of possibilities."

But there's still that one top project he'd like to see others develop someday using his 3D graphics engine -- a 3D version of Nethack. Ironically, this fantasy role-playing game -- a classic among the open-source gaming community -- has usually eschewed fancy visuals. The latest version of this 15-year-old game, released earlier this year, continued with the tradition of rendering the game's graphics in simple ASCII characters.

"I really love Nethack, and I will always keep playing it in ASCII form. But I think that a 3D version of Nethack should be possible," Tyberghein says. "I'd really love to see that happen with Crystal Space."

Howard Wen is a freelance writer who has contributed frequently to O'Reilly Network and written for Salon.com, Playboy.com, and Wired, among others.


Discuss this article in the O'Reilly Network Linux Forum.

Return to the Linux DevCenter.

 

Copyright © 2009 O'Reilly Media, Inc.