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.

Figure 6: The SDL developers are desperately looking for volunteers to update the wiki.

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.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • AIGLX

    Red Hat’s head of X development describes the evolution of AIGLX.

  • Tcl3D

    Tcl3D brings the world of 3D effects to TCL scripting. We’ll show you how to get started with building your own 3D scripts.

  • Pi Flight Simulator

    A Raspberry Pi 4B with Linux can solve the equations for a real-time nonlinear aircraft simulation, including the emulation of modern aircraft flight displays.

  • Xgl and Compiz

    A member of Suse’s X11 team delivers an insider’s look at Xgl.

  • Playful Progress: Blender 2.49 Enhances Game Engine and Panoramic View

    Blender 2.49 is still profiting from its experience developing Big Buck Bunny and the Yo Frankie! Blender game. Much of what goes into the new release is on account of the Game Engine, with its video integration and performance boost.

comments powered by Disqus
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.

Learn More

News