SDL
From DmWiki
SDL (or Simple DirectMedia Layer) is a cross-platform API, which provides subsystems capable of creating games. It could be considered a cross-platform answer to the DirectX API, providing low-level functionality across a variety of operating systems. One of the more interesting concepts of SDL is its marriage with OpenGL, allowing the API to utilize high-performance graphics as well as its atypical simple graphics layer.
SDL has subsystems for sound, input, graphics, CD-ROM, threads, timers, event handling, joystick support and detection, as well as support built-in to the graphics system to allow OpenGL to be called and used alongside its own native SDL API, allowing one to draw flat graphics to the screen, like a HUD using SDL, while rendering the high-performance graphics such as 3D polygonal worlds using OpenGL. It is notable, however, that on Windows-based systems, it is still possible to utilize the DirectX Graphics and other subsystems to use in tandem with the SDL API.
| Table of contents |
Initialization
One of the more popular aspects of the SDL API is its ease of use, especially in initializing, regardless of the platform it is utilized on. This is done simply by making a call to it like follows:
// SDLInit.c
#define <sdl.h>
// We declare that we are using the SDL library and call the main loop
int main(int argc, char *argv)
{
SDL_Init( SDL_INIT_EVERYTHING ); //We initialize all of the SDL subsystems
SDL_Quit( ); //Now we shutdown all of the SDL subsystems
return 0; //End the program
}
Video
While the aforementioned program doesn't do anything useful, it does show the rather simplistic use of the API, initializing SDL with 1 line of code, rather than a dozen like other API often require. If one wants to use the SDL API for video rendering as well, they simple call it as thus:
// SDLInit.c
#define <sdl.h>
// We declare that we are using the SDL library and call the main loop
int main(int argc, char *argv)
{
SDL_Surface *screen; //While not necessary we use an SDL_Surface variable
SDL_Init( SDL_INIT_EVERYTHING ); //We initialize all of the SDL subsystems
screen = SDL_SetVideoMode( 800, 600, 32, SDL_OpenGL | SDL_FULLSCREEN ); //Note that we've also just activated OpenGL at the same time
SDL_Quit( ); //Now we shutdown all of the SDL subsystems
return 0; //End the program
}
Through only 3 lines of code, OpenGL is up and running and ready to draw to the screen. While the SDL_Surface variable is not necessarily needed for this process, it can be used to draw to the screen using SDL as well for HUDs and other flat drawings where we don't want to make polygons for simple 2D graphics.
Audio
While the SDL API is certainly a useful API for simple development, the system is criticized for its lack of higher channel support, featuring only audio in mono or stereo sound, completely omitting sound capabilities for 4-speaker, 5.1, and 7.1 surround sound systems. Due to this, many utilize the OpenAL API instead.
Platforms Supported
- Linux
- Windows
- BeOS
- MacOS Classic
- MacOS X
- FreeBSD
- OpenBSD
- BSD/OS
- Solaris
- IRIX
- QNX
There is also code, but no official support, for
- Windows CE
- AmigaOS
- Dreamcast
- Atari
- NetBSD
- AIX
- OSF/Tru64
- RISC OS
- SymbianOS.
Support Libraries
A complete install of SDL includes several sub-library modules including the SDL_Mixer, SDL_GFX, SDL_Image, SDL_Net and others.
This article is a stub. You can help improve the article by expanding it.
Resources
- SDL Home Page (http://www.libsdl.org/)
- hxRender (http://joel.slylabs.com/?q=node/4) is a utility that allows SDL users to produce faster 2D graphics using OpenGL.
- SDL_Lesson_1:_The_Foundation
