SDL (Simple DirectMedia Layer) - What is SDL?
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 at compile time by checking which operating system the program is being compiled on. This is done through the use of conditional preprocessor directives. Here is a code example of how you would implement platform-specific code blocks in an SDL program:
#ifdef _WIN32 /*Windows code here*/ #endif #ifdef _APPLE_ /*macOS code here*/ #endif #ifdef _linux_ /*Linux code here*/ #endif
These directives check the existence of predefined variables stored within the OS's compiler libraries. Depending on which are defined, the corresponding code will 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 into a unified interface to allow you to 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. SDL also 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 SDL 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 | edit source]
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.
[edit | edit source]