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
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.