SDL (Simple DirectMedia Layer) - What is SDL?

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Simple DirectMedia Layer (SDL) is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video Framebuffer. It is used by MPEG playback software, emulators, and many popular games, including the award winning Linux port of "Civilization: Call To Power". SDL has the word "layer" in its title because it is actually a wrapper library with operating-system-specific functions. The main purpose of SDL is to provide a common framework for accessing these functions. For further functionality beyond this goal, many libraries have been created to work on top of SDL.

Cross-platform programming is achieved by dynamically checking which Operating System the user is running. This is done by the use of conditional macros. Here is a code example of the cross-platform capabilities of SDL:

#ifdef _WIN32
/*Windows specific code here*/
#endif

#ifdef _APPLE_
/*Macintosh OS code here*/
#endif

#ifdef _linux_
/*Linux code here*/
#endif

These macros check the existence of predefined variables stored within the OS's compiler libraries. Depending on which are defined, the corresponding code would be executed for that particular system. This method also prevents OS specific code from conflicting with each other.

The reason for this separation is because Operating systems have different ways of displaying graphics. Even though the code is different in each OS, most perform similar tasks such as creating a window, rendering to the window, grabbing user input, etc.. SDL brings these tasks together on a unified interface to allow you to basically code, compile, and run your program on multiple platforms.

SDL supports Linux, Windows, Windows CE, BeOS, MacOS, Mac OS X, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX. The code contains support for AmigaOS, Dreamcast, Atari, AIX, OSF/Tru64, RISC OS, SymbianOS, and OS/2, but these are not officially supported.

SDL is written in C, but works with C++ natively, and has bindings to several other languages, including Ada, C#, D, Eiffel, Erlang, Euphoria, Go, Guile, Haskell, Java, Lisp, Lua, ML, Oberon/Component Pascal, Objective C, Pascal, Perl, PHP, Pike, Pliant, Python, Ruby, Rust, Smalltalk, and Tcl.

Software developers use it to write computer games and other multimedia applications that can run on many operating systems: Android, iOS, Linux, Mac OS X, Windows and other platforms. It manages video, events, digital audio, CD-ROM, threads, shared object loading, networking and timers. Software developers use it to write computer games and other multimedia applications that can run on many operating systems: Android, iOS, Linux, Mac OS X, Windows and other platforms. It manages video, events, digital audio, CD-ROM, threads, shared object loading, networking and timers.

SDL2[edit]

Simple DirectMedia Layer 2.0 (SDL2) is the second generation of the library. The new version comes with lots of new features such as full 3D hardware acceleration and the less restrictive zlib license.

Clipboard

To do:
List the major changes in SDL2, include examples.

External links[edit]