Simple DirectMedia Layer 2.0
Loop the Loop
In contrast to SDL 1.2, SDL_WaitEvent()
no longer sends the application or the process to sleep. Instead, SDL_WaitEvent()
internally runs through a loop until an event occurs. However, the developers have already said that this behavior might change again in the future.
Final Cleaning
To clean up, you should always release the memory occupied by a texture, destroy the renderer and the window, and wipe down SDL with a damp cloth:
SDL_DestroyTexture(texture); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(mywindow); SDL_Quit();
The complete program is shown in Listing 2. To improve readability, it only fields errors on initialization. You can easily build the program:
gcc -Wall -o helloworld helloworld.c -lSDL2
Listing 2
The Application
The application in Listing 2 only demonstrates how to use a small fraction of the options offered by the SDL. A complete description of the feature scope would fill an entire book. Unfortunately, this kind of documentation is not the developer's favorite subject. The official SDL wiki (Figure 6) provides only an incomplete function reference [5]. Developers are advised to use the comments in the header files as a reference.
Converts from the legacy version 1.2 should read also the Migration Guide [6]. A well-made tutorial for C++ developers can be found on GitHub [7]. All other instructions on the Internet still referred to the legacy SDL 1.2 when this issue went to press.
Conclusions
SDL 2.0 greatly simplifies programming of platform-independent multimedia applications. Listing 2 runs unchanged on all supported systems. The new functions, such as supporting multiple windows and graphics acceleration, were overdue and eliminated the hacks from the past.
As the word "simple" in the name suggests, SDL is still a low-level library that primarily aims to simplify and unify hardware access to multiple platforms. Even the simple drawing functions for rectangles and circles were only added to the new version after the developers received (multiple) requests from users.
If you are looking for fast results, or if you build prototypes, you will probably prefer a games or 3D engine like Pygame, Unity, or Ogre 3D. The developers have postponed some features originally planned for SDL 2.0 to later versions. The idea was to keep the API stable for the time being; changes are only being discussed for version 2.1.
Version 2.0.0 has a few minor bugs [8]; nevertheless, SDL 2.0 is already in use, where stable. New applications should no longer rely on the legacy SDL 1.2 – the future clearly belongs to version 2.0.
Infos
- SDL: http://www.libsdl.org
- Language bindings: http://www.libsdl.org/languages.php
- Official helper libraries: http://hg.libsdl.org/
- List of events: http://wiki.libsdl.org/SDL_EventType?highlight=\bCategoryEnum\b|CategoryEvents|SGEnumerations
- Official SDL wiki: http://wiki.libsdl.org/FrontPage
- Migration Guide: http://wiki.libsdl.org/MigrationGuide
- C++ Tutorial: http://twinklebear.github.io/pages/sdl2/
- Bugtracker: https://bugzilla.libsdl.org/describecomponents.cgi?product=SDL
« Previous 1 2 3 4
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
New Slimbook EVO with Raw AMD Ryzen Power
If you're looking for serious power in a 14" ultrabook that is powered by Linux, Slimbook has just the thing for you.
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.