Game Programming with the Simple DirectMedia Layer

Put the library behind Tux Racer and the Linux version of Civilization into your game.

Animation

The animation routine uses the dirty pixels technique so only
a small portion of the screen is redrawn for each frame. With this
technique, we keep track of the last position in which an object
was drawn and the new position. When Bounce
draws the Earth, first it erases the dirty pixels where it was by
filling them with the background color, and then it draws the Earth
in its new location. We fill rectangles and draw images
using:

SDL_FillRect() fills a rectangle in an SDL_Surface, like the
screen, with a color. The rectangle is specified using an SDL_Rect
structure, and the color is created using SDL_MapRGB().
SDL_BlitSurface() copies a rectangle from one surface into a
rectangle in another surface. If the source rectangle is NULL then
the whole surface is copied. SDL_BlitSurface() is the routine that
applies the color key and takes advantage of RLE encoding.

Summary

SDL reduces the time it takes to write games on Linux. It is
small enough that learning it is a project, not a career, and it is
powerful enough for commercial applications. I hope that between
the information in this article and the source code for
Bounce, you have learned enough of SDL to
start modifying Bounce and building your own
SDL games.

Bob Pendleton's
first programming assignment was to port games from an HP
minicomputer to a UNIVAC mainframe, and he has been fascinated by
computer games ever since. He has been working with various
versions of UNIX and Linux since 1981. He is an independent
software developer and writer. You can reach him at
Bob@Pendleton.com.

Trending Topics

Upcoming Webinar

Getting Started with DevOps - Including New Data on IT Performance from Puppet Labs 2015 State of DevOps Report

August 27, 2015
12:00 PM CDT

DevOps represents a profound change from the way most IT departments have traditionally worked: from siloed teams and high-anxiety releases to everyone collaborating on uneventful and more frequent releases of higher-quality code. It doesn't matter how large or small an organization is, or even whether it's historically slow moving or risk averse — there are ways to adopt DevOps sanely, and get measurable results in just weeks.