Simple DirectMedia Layer
Encyclopedia
Simple DirectMedia Layer (SDL) is a cross-platform
, free and open source multimedia library written in C
that presents a simple interface to various platforms' graphics
, sound, and input devices.
SDL has the word "layer" in its title because it is actually a wrapper
around operating-system-specific functions. The main purpose of SDL is to provide a common framework for accessing these functions.
Software developers use it to write computer games
or other multimedia
applications that can run on many operating system
s including Android, AmigaOS
, AmigaOS 4
, FreeBSD
, BeOS
/Haiku
, iOS, Linux
, Mac OS 9, Mac OS X, MorphOS
, OpenVMS
, PlayStation Portable
, Syllable, Symbian
, webOS, and Windows
. It manages video, events, digital audio, CD-ROM, sound, threads, shared object loading, networking and timers.
by setting up the graphical output and providing mouse and keyboard input, which are beyond the scope of OpenGL.
The library is divided into several subsystems, namely the video (handles both surface functions and OpenGL
), audio, CD-ROM, joystick, and timer subsystems. Besides this basic, low-level support, there also are a few separate official libraries that provide some more functions. These comprise the "standard library", and are provided on the official website and included in the official documentation:
Other, non-standard libraries also exist. For example: SDL_Collide on Sourceforge created by Amir Taaki
.
The SDL library has language binding
s for many programming language
s, from the popular (C
, C++
, Pascal
, Perl
, Python
(via Pygame
), etc.) to the less known (such as Euphoria or Pliant). This, and it being open-source and licensed under the LGPL, makes SDL a common choice for many multimedia applications.
created the library, first releasing it in early 1998, while working for Loki Software
. He got the idea while porting a Windows application to Macintosh. He then used SDL to port Doom to BeOS
(see Doom source port
s). Several other free libraries were developed to work alongside SDL, such as SMPEG
and OpenAL
. He also founded Galaxy Gameworks in 2008 to help commercially support SDL.
SDL 1.3 is a major update to the SDL 1.2 codebase. It replaces several parts of the 1.2 API with more general support for multiple input and output options. Some feature additions include multiple window support, multiple input device support (many mice, many keyboards, etc.), hardware-accelerated 2D graphics, and better Unicode
support. You can look at the roadmap to get a sense of what needs to be done for the move to SDL 1.3/2.0. SDL 1.3, when finished, will eventually become SDL 2.0. SDL 1.3 also introduces a new licensing option, whereby one can obtain a commercial license to allow closed-source static linking. This opens up possibilities for distribution on platforms that do not allow dynamic linking. .
On Microsoft Windows
, SDL uses a GDI
backend by default. A DirectX
backend is also available. Older versions of SDL used DirectX 5, but SDL 1.2 (the current stable release) requires DirectX 7 by default. Sam Lantinga has stated that he plans to use DirectX 8 in future SDL releases.
On X Window System
platforms, including Linux
and OpenVMS
, SDL uses Xlib
to communicate with the X11 system for graphics and events.
On Mac OS X
, SDL uses Quartz
.
Cross-platform
In computing, cross-platform, or multi-platform, is an attribute conferred to computer software or computing methods and concepts that are implemented and inter-operate on multiple computer platforms...
, free and open source multimedia library written in C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
that presents a simple interface to various platforms' graphics
Computer graphics
Computer graphics are graphics created using computers and, more generally, the representation and manipulation of image data by a computer with help from specialized software and hardware....
, sound, and input devices.
SDL has the word "layer" in its title because it is actually a wrapper
Wrapper library
In computer programming, a library is a collection of subroutines or classes used to develop software. Libraries expose interfaces which clients of the library use to execute library routines. Wrapper libraries consist of a thin layer of code which translates a library's existing interface into a...
around operating-system-specific functions. The main purpose of SDL is to provide a common framework for accessing these functions.
Software developers use it to write computer games
Personal computer game
A PC game, also known as a computer game, is a video game played on a personal computer, rather than on a video game console or arcade machine...
or other multimedia
Multimedia
Multimedia is media and content that uses a combination of different content forms. The term can be used as a noun or as an adjective describing a medium as having multiple content forms. The term is used in contrast to media which use only rudimentary computer display such as text-only, or...
applications that can run on many operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...
s including Android, AmigaOS
AmigaOS
AmigaOS is the default native operating system of the Amiga personal computer. It was developed first by Commodore International, and initially introduced in 1985 with the Amiga 1000...
, AmigaOS 4
AmigaOS 4
AmigaOS 4, , is a line of Amiga operating systems which runs on PowerPC microprocessors. It is mainly based on AmigaOS 3.1 source code, and partially on version 3.9 developed by Haage & Partner...
, FreeBSD
FreeBSD
FreeBSD is a free Unix-like operating system descended from AT&T UNIX via BSD UNIX. Although for legal reasons FreeBSD cannot be called “UNIX”, as the direct descendant of BSD UNIX , FreeBSD’s internals and system APIs are UNIX-compliant...
, BeOS
BeOS
BeOS is an operating system for personal computers which began development by Be Inc. in 1991. It was first written to run on BeBox hardware. BeOS was optimized for digital media work and was written to take advantage of modern hardware facilities such as symmetric multiprocessing by utilizing...
/Haiku
Haiku (operating system)
Haiku is a free and open source operating system compatible with BeOS. Its development began in 2001, and the operating system became self-hosting in 2008, with the first alpha release in September 2009, the second in May 2010 and the third in June 2011....
, iOS, Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...
, Mac OS 9, Mac OS X, MorphOS
MorphOS
MorphOS is an Amiga-compatible computer operating system. It is a mixed proprietary and open source OS produced for the Pegasos PowerPC processor based computer, PowerUP accelerator equipped Amiga computers, and a series of Freescale development boards that use the Genesi firmware, including the...
, OpenVMS
OpenVMS
OpenVMS , previously known as VAX-11/VMS, VAX/VMS or VMS, is a computer server operating system that runs on VAX, Alpha and Itanium-based families of computers. Contrary to what its name suggests, OpenVMS is not open source software; however, the source listings are available for purchase...
, PlayStation Portable
PlayStation Portable
The is a handheld game console manufactured and marketed by Sony Corporation Development of the console was announced during E3 2003, and it was unveiled on , 2004, at a Sony press conference before E3 2004...
, Syllable, Symbian
Symbian
Symbian is a mobile operating system and computing platform designed for smartphones and currently maintained by Accenture. The Symbian platform is the successor to Symbian OS and Nokia Series 60; unlike Symbian OS, which needed an additional user interface system, Symbian includes a user...
, webOS, and Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
. It manages video, events, digital audio, CD-ROM, sound, threads, shared object loading, networking and timers.
Design
SDL itself is very simple; it merely acts as a thin, cross-platform wrapper, providing support for 2D pixel operations, sound, file access, event handling, timing, threading, and more. It is often used to complement OpenGLOpenGL
OpenGL is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. OpenGL...
by setting up the graphical output and providing mouse and keyboard input, which are beyond the scope of OpenGL.
The library is divided into several subsystems, namely the video (handles both surface functions and OpenGL
OpenGL
OpenGL is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. OpenGL...
), audio, CD-ROM, joystick, and timer subsystems. Besides this basic, low-level support, there also are a few separate official libraries that provide some more functions. These comprise the "standard library", and are provided on the official website and included in the official documentation:
- SDL_image — support for multiple image formats
- SDL_mixer — complex audio functions, mainly for sound mixing
- SDL_net — networking support
- SDL_ttf — TrueTypeTrueTypeTrueType is an outline font standard originally developed by Apple Computer in the late 1980s as a competitor to Adobe's Type 1 fonts used in PostScript...
font rendering support - SDL_rtf — simple Rich Text FormatRich Text FormatThe Rich Text Format is a proprietary document file format with published specification developed by Microsoft Corporation since 1987 for Microsoft products and for cross-platform document interchange....
rendering
Other, non-standard libraries also exist. For example: SDL_Collide on Sourceforge created by Amir Taaki
Amir Taaki
Amir Taaki is a British video game and computer software developer. Taaki is best known as the chairman of the Bitcoin Consultancy, as a Bitcoin project developer and for pioneering many open source projects.-Early years:...
.
The SDL library has language binding
Language binding
In computing, a binding from a programming language to a library or OS service is an API providing that service in the language.Many software libraries are written in systems programming languages such as C or C++...
s for many programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....
s, from the popular (C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
, C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
, Pascal
Pascal (programming language)
Pascal is an influential imperative and procedural programming language, designed in 1968/9 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming and data structuring.A derivative known as Object Pascal...
, Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...
, Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
(via Pygame
Pygame
Pygame is a cross-platform set of Python modules designed for writing video games.It includes computer graphics and sound libraries designed to be used with the Python programming language...
), etc.) to the less known (such as Euphoria or Pliant). This, and it being open-source and licensed under the LGPL, makes SDL a common choice for many multimedia applications.
History
Sam LantingaSam Lantinga
Sam Oscar Lantinga was the lead software engineer at Blizzard Entertainment, where he is known to the community as Slouken. He may be most famous as the creator of the Simple DirectMedia Layer, a very popular open source multimedia programming library, and also developed the compatibility database...
created the library, first releasing it in early 1998, while working for Loki Software
Loki Software
Loki Software, Inc. was a software firm based in Tustin, California, United States, that ported several video games from Microsoft Windows to Linux...
. He got the idea while porting a Windows application to Macintosh. He then used SDL to port Doom to BeOS
BeOS
BeOS is an operating system for personal computers which began development by Be Inc. in 1991. It was first written to run on BeBox hardware. BeOS was optimized for digital media work and was written to take advantage of modern hardware facilities such as symmetric multiprocessing by utilizing...
(see Doom source port
Doom source port
A Doom source port is a source port of id Tech 1, the game engine used by the video game Doom. The term usually denotes a modification made by Doom fans, as opposed to any of the official Doom versions produced by id Software or affiliated companies.-Doom source release:The source code for the Doom...
s). Several other free libraries were developed to work alongside SDL, such as SMPEG
SMPEG
SMPEG is short for the SDL MPEG library originally developed by Loki Software. Since both it and SDL are free software under the LGPL, it uses the MPEG-1 standard as a video display library, rather than MPEG-2, since only the MPEG-1 standard is unencumbered with software patents in the United...
and OpenAL
OpenAL
OpenAL is a cross-platform audio API. It is designed for efficient rendering of multichannel three dimensional positional audio. Its API style and conventions deliberately resemble those of OpenGL.- History :...
. He also founded Galaxy Gameworks in 2008 to help commercially support SDL.
SDL 1.3 is a major update to the SDL 1.2 codebase. It replaces several parts of the 1.2 API with more general support for multiple input and output options. Some feature additions include multiple window support, multiple input device support (many mice, many keyboards, etc.), hardware-accelerated 2D graphics, and better Unicode
Unicode
Unicode is a computing industry standard for the consistent encoding, representation and handling of text expressed in most of the world's writing systems...
support. You can look at the roadmap to get a sense of what needs to be done for the move to SDL 1.3/2.0. SDL 1.3, when finished, will eventually become SDL 2.0. SDL 1.3 also introduces a new licensing option, whereby one can obtain a commercial license to allow closed-source static linking. This opens up possibilities for distribution on platforms that do not allow dynamic linking. .
Ports
Because of the way SDL is designed, much of the source code is split into separate modules for each operating system, to make calls to the underlying system. When SDL is compiled, the correct modules are selected for the target system.On Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
, SDL uses a GDI
Graphics Device Interface
The Graphics Device Interface is a Microsoft Windows application programming interface and core operating system component responsible for representing graphical objects and transmitting them to output devices such as monitors and printers....
backend by default. A DirectX
DirectX
Microsoft DirectX is a collection of application programming interfaces for handling tasks related to multimedia, especially game programming and video, on Microsoft platforms. Originally, the names of these APIs all began with Direct, such as Direct3D, DirectDraw, DirectMusic, DirectPlay,...
backend is also available. Older versions of SDL used DirectX 5, but SDL 1.2 (the current stable release) requires DirectX 7 by default. Sam Lantinga has stated that he plans to use DirectX 8 in future SDL releases.
On X Window System
X Window System
The X window system is a computer software system and network protocol that provides a basis for graphical user interfaces and rich input device capability for networked computers...
platforms, including Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...
and OpenVMS
OpenVMS
OpenVMS , previously known as VAX-11/VMS, VAX/VMS or VMS, is a computer server operating system that runs on VAX, Alpha and Itanium-based families of computers. Contrary to what its name suggests, OpenVMS is not open source software; however, the source listings are available for purchase...
, SDL uses Xlib
Xlib
Xlib is an X Window System protocol client library written in the C programming language. It contains functions for interacting with an X server. These functions allow programmers to write programs without knowing the details of the protocol...
to communicate with the X11 system for graphics and events.
On Mac OS X
Mac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...
, SDL uses Quartz
Quartz (graphics layer)
Quartz specifically refers to a pair of Mac OS X technologies, each part of the Core Graphics framework: Quartz 2D and Quartz Compositor. It includes both a 2D renderer in Core Graphics and the composition engine that sends instructions to the graphics card...
.
Syntax and subsystems
The syntax of SDL is function-based: all operations done in SDL are done by passing parameters to functions. Special structures are also used to store the specific information SDL needs to handle. There are a few different subsystems SDL categorizes its functions under:- The video, events and threads subsystem: this provides functions for video, multi-threadingThread (computer science)In computer science, a thread of execution is the smallest unit of processing that can be scheduled by an operating system. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process...
, and event handling - The audio subsystem: this provides functions for audio
- The time subsystem
- The joystick subsystem
- The CD-ROM subsystem
See also
- List of games using SDL
- Allegro libraryAllegro libraryAllegro is a free and open source software library for video game development.The functionality of the library includes support for basic 2D graphics, image manipulation, text output, audio output, midi music, input and timers, as well as additional routines for fixed-point and floating-point...
- Cross-Platform Support MiddlewareCross-Platform Support MiddlewareA cross-platform support middleware is a software abstraction layer that guarantees the existence, and correct implementation, of a set of services on top a set of platforms.-Formal model:Formally, a CPSM can be represented by the following model:...
- DirectXDirectXMicrosoft DirectX is a collection of application programming interfaces for handling tasks related to multimedia, especially game programming and video, on Microsoft platforms. Originally, the names of these APIs all began with Direct, such as Direct3D, DirectDraw, DirectMusic, DirectPlay,...
- General Graphics InterfaceGeneral Graphics InterfaceGeneral Graphics Interface is a project that aims to develop a reliable, stable and fast computer graphics system that works everywhere...
- OpenGLOpenGLOpenGL is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. OpenGL...
- OpenMLOpenMLOpen Media Library is a free, cross-platform programming environment designed by the Khronos Group for capturing, transporting, processing, displaying, and synchronizing digital media .-See also:* SDL* Allegro* ClanLib* OpenGL* OpenAL* PLIB-External links:* *...
- pygamePygamePygame is a cross-platform set of Python modules designed for writing video games.It includes computer graphics and sound libraries designed to be used with the Python programming language...
Further reading
- Alberto García Serrano: Programación de videojuegos en SDL, Ediversitas, ISBN 8495836084 (spanish)
- Ernest Pazera: Focus On SDL, Muska & Lipman/Premier-Trade, ISBN 1592000304
- Ron Penton: Data Structures for Game Programmers, Muska & Lipman/Premier-Trade, ISBN 1931841942 (game programming examples with SDL)
- John R. Hall: Programming Linux Games, No Starch, ISBN 1886411492 (First SDL book, by Loki Games, archived online version: PDF, LaTex sources)