Linux Game Programming for PC & Embedded Systems using SDL
Presented by
Fore June
Author of Windows Fan, Linux Fan

Games and SDL
SDL Installation
SDL for Embedded
SDL API
SDL Events
 SDL Graphics
SDL Threads
Thread Example
SDL Animation
SDL Sound
 Raw Video Player
Video Formats
Video Compression
 Game Trees
About The Author

An Introduction to Video Compression in C/C++ now available at Amazon

An Introduction to Digital Video Compression in Java now available at Amazon
An Introduction to Digital Video Data Compression in Java now available at Amazon
Click here to see table of contents.

@Copyright by Fore June, 2006

SDL Installation

  1. Installation

    Most likely, your Linux system already has SDL and related packages installed. In cases your system does not have or you want to upgrade the packages, you can download them directly from the site SDL site ( http://www.libsdl.org ). More precisely, the packages can be found at the following links.

    SDL-: http://www.libsdl.org/download-1.2.php
      The basic SDL package that lets us do graphics, and I/Os like mouse and keyboard.

    SDL_image- :http://www.libsdl.org/projects/SDL_image/
      Image library that helps you to load images of BMP, GIF, JPEG, LBM, PCX, PNG, PNM, TGA, TIFF, XCF, XPM, XV

    SDL_net- : http://www.libsdl.org/projects/SDL_net/

    SDL_ttf- : http://www.libsdl.org/projects/SDL_ttf/
      A sample library that allows you to use TrueType fonts in your SDL applications. It comes with an example program "showfont" which displays an example string for a given TrueType font file.

    SDL_mixer-: http://www.libsdl.org/projects/SDL_mixer/
      A sample multi-channel audio mixer library. It supports any number of simultaneously playing channels of 16 bit stereo audio, plus a single channel of music, mixed by the popular MikMod MOD, Timidity MIDI, Ogg Vorbis, and SMPEG MP3 libraries.

    SDL_sound-: http://icculus.org/SDL_sound/downloads/
      A library that handles the decoding of several popular sound file formats, such as .OGG, .WAV and .MP3. It is meant to make the programmer's sound playback tasks simpler.

    The installation processes of the above packages are all very similar to each other. We'll use the SDL-1.2.11.tar.gz package as an example to illustrate the steps. First, you can browse the sites and download the desired packages by clicking on their links. Or more conveniently, you may use the wget command to acquire it; you first go to a directory and issue the command

    $wget url

    where url is the URL link to the package. For example, the following command

    $wget http://www.libsdl.org/release/SDL-1.2.11.tar.gz

    downloads the SDL package into your desired directory, say, /download. ( You may obtain the complete URL of the package by first using a browser to access the page containing a link to it and pointing at it with the mouse; pressing the right button of the mouse let you choose to copy the link. ) You can then implode it into another directory by

    $gunzip -c /download/SDL-1.2.11.tar.gz | tar xvf -
    $cd SDL-1.2.11

    You should find the files "README" and "INSTALL" in the directory. Read the files to obtain the information of installation. If you simply plan to use the default setting, the following three commands will do the job.

    $./configure
    $make
    #make install

    The command configure set up the installation directories and the optional features of of the package. As no arguments are provided, default settings will be used. The SDL library will be installed in the directory /usr/local/lib. After make install the library is ready for use; you need to include <SDL/SDL.h> in your program and link it with -lSDL when compiling your application. If you want to find out other options that you can have, use the command

    $./configure --help | less

    and scroll through the menu displayed.

  2. Installation for Embedded Systems

    Nowadays, the most popular embedded processors are the ARM processors ( http://www.arm.com ). Over the last decade, the ARM architecture has become the most pervasive 32-bit architecture in the world, with more than 2 billion ARM-based processors shipped. Throughout this book, our discussion involved embedded systems will be centered around the ARM processor core. There are two commonly used compilers for ARM processors, namely, arm-elf-linux-g++ for ARM 7 products and arm-linux-g++ for ARM 9 products.

    Though the installation of SDL packages to be used for embedded systems is similar to the case for PC, very often we need to do some customization of selected features when doing configure. A convenient way to handle this is to write a simple script to set the desired configuration choices. Suppose, without loss of generality, we want to install all the SDL libraries for ARM processors in the directory /arm. The following is a sample script, named arm_configure.sh to handle this.

    #!/bin/sh
    
    export INSTALL_PATH=/arm
    
    if [ $1 ]
    then
    #for ARM7
      export USER_HOST=arm-elf-linux
      export USER_CROSS_COMPILE=arm-elf-
    else
    #for ARM9
      export USER_HOST=arm-linux
      export USER_CROSS_COMPILE=arm-linux-
    fi
    
    export USER_CFLAGS="-I${INSTALL_PATH}/include/"
    export USER_LDFLAGS="-L${INSTALL_PATH}/lib/"
    
    export USER_CC="${USER_CROSS_COMPILE}gcc"
    export USER_CXX="${USER_CROSS_COMPILE}g++"
    export USER_AR="${USER_CROSS_COMPILE}ar"
    
    PRIV_FLAGS=
    if [ ${USER_HOST} = "arm-linux" ]
    then
      PRIV_FLAGS="-DDISABLE_MOUSE -D__ARM__"
    elif [ ${USER_HOST} = "arm-elf-linux" ]
    then
      PRIV_FLAGS="-DDISABLE_MOUSE -D__ARM__"
    fi
    
    #PRIV_FLAGS="-D__ARM__  -DFBCON_DEBUG"
    ./configure \
    --prefix=${INSTALL_PATH} \
    --host=${USER_HOST}  \
    --enable-static \
    --disable-shared \
    --disable-joystick \
    --disable-cdrom \
    --disable-esd \
    --disable-nasm \
    --enable-video-fbcon \
    --enable-video-opengl \
    --enable-osmesa-shared \
    --disable-arts \
    --disable-alsa \
    --without-x \
    --enable-debug \
    --enable-loadso \
    CC=${USER_CC} \
    CXX=${USER_CXX} \
    CFLAGS=" ${USER_CFLAGS} ${PRIV_FLAGS} -DFBCON_DEBUG -DNO_SIGNAL_H " \
    LDFLAGS=${USER_LDFLAGS}
    make
    make install
    
    You can save the script in a file named arm_configure.sh and make it executable by $chmod +x arm_configure.sh If you are using ARM9, you can simply execute the script, $./arm_configure.sh which does the configuration and install the libraries in /arm and its subdirctories. If you are using ARM7, supply an argument for the script. For example, $./arm_configure.sh ARM7

    Note that in the script, we have disabled the mouse meaning that we won't use any mouse in the ARM board. Of course, this would not make your embedded programs very interested. If we want to enable the mouse or touch-screen feature for an ARM board, which usually does the interface via the USB port, we need to do some modifications to the SDL files. We will discuss this in later chapters.