Friday, November 21, 2008

3D Game Engines, part 1

While I was in college, I worked ahead of my classes with a 2D graphics library called Allegro. After I graduated, I proceeded to work with SDL, Gosu, Irrlicht, and Ogre3D (in that order. ) Any field of computer science is an unending journey of learning, but I would still consider myself enough of an authority on graphics engines to write on the subject. In fact, that's why my friend Matt suggested that I start this blog.

This will be part 1 of a series, as there's a lot of ground to cover and I want to be detailed. I want to teach the aspects of this subject that slowed me down, so that other programmers won't have to muddle through it like I did.

For part 1, I'm just going to go over all of the engines I've fiddled with and describe them to you, so that you can decide what you want to mess with. This won't help much in terms of use, but it will allow you to pick a starting place and give you time to get familiar with its community. If you've never installed a library before, I suggest asking google since that's a fairly lengthy subject, but it generally goes something like this:

Step 1: In Windows, download/install the SDK. In Linux, compile the source code, or look for a package ( for example, in Ubuntu a lot of libraries are in the repositories, all you have to do is apt-get install the one you want! ) Sometimes you have to compile source in Windows, too. Don't worry, it's not that hard, and you have more control over the result. I always reccomend doing the compiling if you can, but if you're an absolute beginner you can pick something with a package or SDK.

Step 2: Link to it. A library is compiled ( or packaged that way ) not because its a program, but because all of its source code does NOT need to be compiled over and over every time you want to test your program. You just link to it. This speeds up development significantly. You usually link to one or more dll or object files, which is either placed in your system's path ( /windows/system32 or /usr/lib ) or in the folder of your project. Actually, you can put it anywhere, as long as your project can find it! Most IDEs, for example, CodeBlocks, are good about setting up directories. Just go to the build option and pick where you stashed your object files. Again, this is not required if you have it in your path.

Step 3: Include the headers. The rules are the same. The headers will be in a folder somewhere, and they tell the program what the API (syntax) of the library is. These have to be found by the compiler too. Like the binary, this can either be via the system path, or a preferred location.

And that's all, you just have to include the headers you need into your project and it should work. Each library has its own documentation for how to do this.


Without further ado, The libraries!


Click the name for a link to the official website

ALLEGRO: Allegro is programmed in C, but it's pretty high level. It does have a few globals, but it wraps well in C++ if you intend on using classes. All of this aside, Allegro is a fantastic library that is made to be easy and fun. It's mostly 2D, but very fast and very high quality. http://www.allegro.cc shows just how many wonderful projects have been made in it. Some of them are extremely impressive!
Please note that this library has recently undergone some serious renovations, so if you get the latest version, it will be a totally different library from the one I've been using. I reccomend it though, because it's more standardized and simpler to read.

SDL: It's faster than Allegro, and uses OpenGL, but it's harder. It doesn't come with a lot of easy functions like flipping and rotating, filling, drawing primitives, and so forth. There are modular libraries that can be added to SDL to make it do these things, but they dont come bundled. SDL does have a lot of documentation, and using it will teach you more about 2D than Allegro will, since Allegro does the work for you. SDL has been used commercially quite a bit. It's a C library, like Allegro.

Gosu: Easy as it gets. Gosu is designed to be very strict in form, simple, and elegant. Development in Gosu is FAST. I had a whole engine working from scratch in under 3 days. The downside is that it hides everything for you. You can't, for example, directly alter loaded images. So if you want to animate an explosion within the program, you're out of luck - you'll have to do that as a little animation that gets imported. This isn't usually an issue.
Gosu is C++ all the way, and forces the use of Boost pointers, so to use this library you'll need to get Boost too. But this is a good thing; boost pointers delete themselves! No memory leaks :) And it's going to be added to the C++ standard eventually anyway, so it wouldn't be a bad idea to learn how Boost works.

Irrlicht: My first 3D graphics engine. Actually, my first was CrystalSpace, but that one is way too complicated to start with. Irrlicht, however, is the easiest I've messed with. It has built in collision detection, physics, and shadow effects. However, it's buggy. The stencil shadows have a lot of issues that are still needing correction. On some ATI linux machines they flicker wildly. It's also just not very powerful, and doesn't offer you as many options as the next library. But for beginners, that may be a good thing. Irrlicht is C++.

Ogre3D: This is what I finally decided upon. Ogre3D is easy, powerful, flexible, and MASSIVE. As an example, Irrlicht has just one shadow type, but Ogre3D has six. It is also made to be modular. It does not come with physics, or collision detection, or anything like that, but the massive community has contributed code that lets you link it up easily with other libraries. Ogre3D also comes with a sample framework that lets you jump right into programming a scene without any setup, all in a single function. Used in conjunction with the tutorials on the website, this is quite powerful. Also C++


If you're a Java user, look into JMonkey. If you prefer python, Disney's Panda3D is your weapon of choice. And I should mention, if you're a fan of Ruby, most of the Gosu community uses that instead of C++ ( but there's support for both ).




This should help you get started. Using this information and a little google-fu, you should be able to pick a library and set it up fairly easily. I'll be writing on Allegro and Ogre3D, since those encompass the 2D and 3D programming provided in the list. If you choose something else, you should be able to apply anything I say. Libraries aren't all that different, really.

Anyway, good luck, and see you next time!

No comments: