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
-
Linux Kernel 6.13 Offers Improvements for AMD/Apple Users
The latest Linux kernel is now available, and it includes plenty of improvements, especially for those who use AMD or Apple-based systems.
-
Gnome 48 Debuts New Audio Player
To date, the audio player found within the Gnome desktop has been meh at best, but with the upcoming release that all changes.
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.
-
HashiCorp Cofounder Unveils Ghostty, a Linux Terminal App
Ghostty is a new Linux terminal app that's fast, feature-rich, and offers a platform-native GUI while remaining cross-platform.
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.