Simple DirectMedia Layer----一套开源的跨平台多媒体开发库

时间:2021-07-29 02:18:59

        SDL库的作用说白了就是封装了复杂的视音频底层操作,简化了视音频处理的难度。使用C语言写成,是一套开放源代码的跨平台多媒体开发库。

        SDL提供了数种控制图像、声音、输入/出的函数,让开发者只要用相同或是相似的代码就可以开发出跨多个平台(Linux、Windows、Mac OS X等)的应用软件。目前SDL多用于开发游戏、模拟器、媒体播放器等多媒体应用领域。SDL使用GNU宽通用公共许可证为授权方式,意指动态链接(dynamic link)其库并不需要开放本身的源代码。因此诸如《雷神之锤4》等商业游戏也使用SDL来开发。

1、结构
        虽然SDL时常被比较为‘跨平台的DirectX’,然而事实上SDL是定位成以精简的方式来完成基础的功能,它大幅度简化了控制图像、声音、输入/出等工作所需撰写的代码。但更高级的绘图功能或是音效功能则需搭配OpenGL和OpenAL等API来达成。另外它本身也没有方便创建图形用户界面的函数。
        SDL在结构上是将不同操作系统的库再包装成相同的函数,例如SDL在Windows平台上其实是DirectX的再包装,而在使用X11的平台上(包括Linux),SDL则是与Xlib库沟通来输出图像。虽然SDL本身是使用C语言写成,但是它几乎可以被所有的编程语言所使用,例如:C++、Perl、Python(借由PySDL2.0库)、Pascal等等,甚至是Euphoria、Pliant这类较不流行的编程语言也都可行。

Simple DirectMedia Layer----一套开源的跨平台多媒体开发库

2、子系统

        SDL is divided into several subsystems:

Basics----
Initialization and Shutdown, Configuration Variables, Error Handling, Log Handling
Video------
Display and Window Management, surface functions, rendering acceleration, etc.
Input Events
Event handling, Support for Keyboard, Mouse, Joystick and Game controller
Force Feedback
SDL_haptic.h implements support for "Force Feedback"
Audio------
SDL_audio.h implements Audio Device Management, Playing and Recording
Threads--
multi-threading: Thread Management, Thread Synchronization Primitives, Atomic Operations
Timers----
Timer Support
File Abstraction
Filesystem Paths, File I/O Abstraction
Shared Object Support
Shared Object Loading and Function Lookup
Platform and CPU Information
Platform Detection, CPU Feature Detection, Byte Order and Byte Swapping, Bit Manipulation
Power Management
Power Management Status
Additional
Platform-specific functionality

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的“标准库”)

  • SDL_image — support for multiple image formats(支持时下流行的图像格式)
  • SDL_mixer — complex audio functions, mainly for sound mixing(更多的声音输出函数以及更多的声音格式支持)
  • SDL_net — networking support(网络支持)
  • SDL_ttfTrueType font rendering support(TrueType字体渲染支持)
  • SDL_rtf — simple Rich Text Format rendering(简单的RTF渲染支持)

Other, non-standard libraries also exist. For example: SDL_Collide on Sourceforge created byAmir Taaki.

3、SDL与DirectX比较对应关系

SDL DirectX 说明
SDL_Video、SDL_Image、OpenGL DirectDraw、Direct3D  
SDL_Audio、SDL_Mixer DirectSound  
SDL_Joystick、SDL_Base DirectInput  
SDL_Net DirectPlay  
SMPEG、SDL_Video、SDL_Audio、SDL_Sound、SDL_Filter DirectShow  
4、使用SDL开发的游戏:

《Spore》

《Tux Paint》
《Simutrans》
《Stepmania》
《Frozen Bubble》
《无冬之夜》(Neverwinter Nights)
《魔法门之英雄无敌III》(Heroes of Might and Magic III)(Linux版)
《模拟城市3000》(Sim City 3000)(Linux版)
《虚幻竞技场》(Unreal Tournament)(Linux版)
《虚幻竞技场2003》(Unreal Tournament 2003)(Linux版)
《虚幻竞技场2004》(Unreal Tournament 2004)(Linux版)
《第二人生》(Second Life)(Linux版)
《佣兵战场》(Soldier of Fortune)(Linux版)
《韦诺之战》(Battle for Wesnoth)