Jump to content

Simple DirectMedia Layer

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Witchinghour (talk | contribs) at 19:14, 10 June 2007 (→‎See also: rm dead link). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Simple DirectMedia Layer
Developer(s)Sam Lantinga
Stable release
1.2.11 / June 26, 2006
Repository
Operating systemCross-platform
TypeAPI
LicenseGNU Lesser General Public License
Websitelibsdl.org

Simple DirectMedia Layer (SDL) is a cross-platform, multimedia, free software library written in C that creates an abstraction over various platforms' graphics, sound, and input APIs, allowing a developer to write a computer game or other multimedia application once and run it on many operating systems including Linux, Windows and Mac OS X. It manages video, events, digital audio, CD-ROM, sound, threads, shared object loading, networking and timers.

History

Sam Lantinga 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 ports). Several other free libraries appeared to work with SDL, such as SMPEG and OpenAL.

The SDL library has bindings with almost every programming language there is, from the popular (C++, Perl, Python (through pygame), Pascal etc.) to the less known (such as Euphoria or Pliant). This and the fact that it is open-source and licensed under the LGPL make SDL a common choice for many multimedia applications.

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. OpenGL is often used with SDL to provide fast 3D rendering. It is often thought of as a cross-platform DirectX, although it lacks some of its more advanced functionality. SDL instead has a huge number of third party extensions that make it easy to do more advanced functions.

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 additional functionality. These comprise the "standard library", and are provided on the official website and included in the official documentation:

  • SDL_image - Is used in conjunction with SDL to provide support for modern image formats. It is maintained by Sam Lantinga and Mattias Engdegård, and is currently able to load the following formats: BMP, PPM, XPM, PCX, GIF, JPEG, PNG, and TGA. This extension is necessary since the main SDL library only provides a way to load and save in the BMP format. Although SDL_image adds support for loading images, there is currently no way of saving images in any other format than BMP. Besides the core SDL library, SDL_image also needs the IJG, PNG, Zlib and SGI TIFF libraries for loading some of the formats. In the C/C++ binding, SDL_image provides the function IMG_Load( const char* ) and a few variations all of which return a pointer to a SDL_Surface where the loaded image is stored.
  • SDL_mixer (complex audio functions, mainly for sound mixing)
  • SDL_net (networking support)
  • SDL_ttf (TrueType Font rendering support)
  • SDL_rtf (simple Rich Text Format rendering).

SDL.Net

SDL.NET is a set of object-oriented CLI-compliant .NET bindings for the Simple DirectMedia Layer gaming library written by David Y. Hudson. It provides high-level access to audio, keyboard, mouse, joystick, TrueType fonts, various image formats, sound mixing, MPEG-1 movies and 3D hardware via OpenGL and 2D video framebuffer.

Architecture

Abstraction layers of several SDL platforms.

SDL has the word "layer" in its title because it is actually a wrapper around operating-system-specific functionality. The chief purpose of SDL is to provide a common framework for accessing this functionality.

Because of the way SDL is designed, a lot of the source code is split into separate modules for each operating system, in order to make calls to the underlying system. When SDL is compiled, the correct modules are selected for the target system.

On Microsoft Windows, SDL actually wraps around DirectX, which in turn wraps around the video driver; SDL is useful for porting to Windows, but merely replicates DirectX functions otherwise. Older versions 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[1].

On X11 platforms, including Linux, SDL uses Xlib to communicate with the X11 system for graphics and events.

On Mac OS X, it uses Quartz.

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 functionality for video, multi-threading, and event handling.
  • The Audio subsystem - this provides audio functionality.
  • The Time subsystem
  • The Joystick subsystem
  • The CD-ROM subsystem

Example code (C)

// Headers
#include "SDL/SDL.h"

// Main function
int main( int argc, char* argv[] )
{
    // Initialize SDL
    if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
        return( 1 );

    // Delay 2 seconds
    SDL_Delay( 2000 );

    // Quit SDL
    SDL_Quit();

    // Return
    return 0;
}

A very basic SDL program. It loads SDL subsystems, pauses for 2 seconds, closes SDL, then exits the program.

Games using SDL

See List of games using SDL for a more complete list

Extensions

  • SMPEG - SDL MPEG Player Library
  • Guichan and ParaGUI - Widget Sets
  • GGI - a free cross-platform graphics interface

See also