SDL is a cross-platform library developed by Sam Lantinga who is behind the Galaxy Game Works that provides low-level access to various platforms' graphics, sound, and input devices. In short, it enables you to write games, emulators,demos or multimedia software that runs on different platforms, officially on Linux, Windows, Windows CE, BeOS, MacOS, Mac OS X, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX and unofficially on AmigaOS, Dreamcast, Atari, AIX, OSF/Tru64, RISC OS, SymbianOS, and OS/2.
- Read more on Games Programming Articles
It's written in C, but works with C++ natively and has bindings to Ada, C#, D, Eiffel, Erlang, Euphoria, Go, Guile, Haskell, Java, Lisp, Lua, ML, Objective C, Pascal, Perl, PHP, Pike, Pliant, Python, Ruby, Smalltalk, and Tcl.
It's licensed under a liberal Zlib license and the only requirement for commercial use is that it links to the dynamic libvrary version e.g. SDL dll on Windows, .so on Linux. It's free, both to use and royalty free. Of course if you make money using it, a donation to the project would go down well.
As one article about SDL says, the basic philosophy of SDL is a combination of "lean and mean" and "Keep It Simple."
- Find more Games in C in the Games C Library
It's Not DirectX or XNA
On Windows, if you're not worried about other platforms, you might use the alternatives such as DirectX (C++) or XNA (C#) and being Microsoft technologies, those are closer aligned to Windows. On Windows, SDL uses an older version of DirectX and OpenGL on other platforms. Consider it as a thin wrapper. Version 1.3 is a big catchup with full 3D hardware acceleration, support for multi touch (ueful on mobile devices sucgha iOS and Android etc.
SDL 1.3 Functionality
As of October 2, 2011 SDL 1.3 compiles and is thoroughly tested for release for Windows XP, Windows Vista, Windows 7, Mac OS X 10.4+, Linux 2.6+, iOS 3.1.3+ and Android 1.6+. So all the games tutorials will use it. The documentation is a bit 1.2ish in places but I figure that it will continue to improve and 1.3 will become the new default
SDL splits into these areas:
- Video: set mode, write to framebuffers
- Input Events
- Force Feedback where supported in Windows, Mac OS X and Linux
- File I/O Abstraction
- Shared Objects in DLLS, .dylibs (Max OS X) and .so on Linux
If you're interested, read the full feature list.
SDL Has Many Headers
It's just a matter of mix and matching the thirty+ headers. These are all prefixed with SDL, so along with SDL.h which is needed to initialize and shutdown SDL.
The SDL_Init initializes Event Handling, File I/o and threading and the two extra aparemetrs there also initialize Video and Audio. Although you can initialize specified sub-system later, when it comes time to close down, one call to SQL_QUIT() will close down all the used sub-systems.
There are some 70 functions just for video and Window management and another 44 in the 2D accelerated rendering. Other headers include SDL_Pixels.h for pixel formats and conversion, SDL_rect.h for managing rectangles, SDL_surface.h for surface creation and some others for platform specific window management and clipboard handling.
SDL is very rich in functions. Timers? Check, with six functions for adding timers, doing delays (down to 10 ms), Want to know if the CPU supports a given feature? check.
The SDL Ecosystem
There are currently 179 libraries available on the SDL libraries page, including 113 that are 100% and cross platform. Likewise there are 500+ completed games out of 600+. Some of these have source code on source code repositories like source forge, and there are a number of comercial games showing just how popular SDL is.
SDL 1.2 v SDL 1.3
SDL 1.2 has been around a long while SDL is about 14 years old. Consequently most of waht you read on SDL will be about 1.2 and the two are generally compatible. There is a substantial wiki (thanks to spammers, you have to apply to have wiki change permission) and a migration guide from 1.2 to 1.3. The main changes are in surface handling and multiple screen support. But there seems a good chance that most 1.2 code will work in 1.3
SDL is a mature, highly respected project and ideal for anyone wanting to write Linux or cross project games, or non game applications (there are 125 currently listed). There is a lot of documentation (you might prefer the downloadable version) but it is mostly 1.2. It will take a time for it to migrate to 1.3 though I'm sure volunteers would be well received.
- (Coming soon) Read about the Snake SDL Game Tutorial Four (To be published in October 2011)