Microsoft & .NETVisual C#Cross-Platform Game Development for C++ Developers, Part II: The Allegro Platform

Cross-Platform Game Development for C++ Developers, Part II: The Allegro Platform content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

Good news, would-be game developers: I am extending my introduction to cross-platform game development into a weekly series. This week, I highlight the Allegro (Allegro Low LEvel Game ROutines) open source library, going into technical depth and providing a brief demo, so you can determine if it’s the right platform for you.

An Engine for Many Environments

Every program that uses audio should call reserve_voices() to specify the number of voices that the digital and MIDI sound drivers use, respectively. Later on, you can control the mixing of these audio channels.

You can insert an audio track as easily as this:

MIDI *midFile =  load_midi("myfile.mid');
play_midi(midFile, TRUE);    // loop continuously

For more sophisticated needs, you can install one of three hook functions that allow you to intercept MIDI player events. If set to anything other than NULL, these routines will be called for each MIDI message, meta-event, and system-exclusive data block, respectively.

Allegro’s digital audio system is designed from the ground up to be extensible. You can easily install readers and writers to handle new or variant audio file types, for example:

register_sample_file_type("mp3", load_mp3, NULL);    // install my
                                                     // MP3 reader

Digital audio can be edited on the fly, while it is playing. The following code alters the parameters of a sample while it is playing (useful for manipulating looped sounds):

void adjust_sample(const SAMPLE *spl, int vol, int pan, int freq,
                   int loop);

You can alter the volume, pan, and frequency, and clear the loop flag, which will stop the sample when it next reaches the end of its loop. If several copies of the same sample are playing, this will adjust the first one it comes across. If the sample is not playing, it has no effect.

Learn More About Allegro


If you prefer a step-by-step approach to learning Allegro, you can’t do better than Game Programming All in One, 2nd Ed by Jonathan Harbour (ISBN 1-59200-383-4). It works through the core features of the Allegro game library and demonstrates writing code to load images, manipulate sprites, scroll the background, use double-buffering, read a joystick, detect collisions, and implement other core features of any game. Each new chapter builds on the game already in progress.

Along the way, you’ll learn about game theory, including artificial intelligence, game physics, mathematics, algorithms, and multiplayer programming, which are integrated into the featured game. The publisher even includes a CD-ROM so you have everything you need to get started.

About the Author

Victor Volkman has been writing for C/C++ Users Journal and other programming journals since the late 1980s. He is a graduate of Michigan Tech and a faculty advisor board member for Washtenaw Community College CIS department. Volkman is the editor of numerous books, including C/C++ Treasure Chest and is the owner of Loving Healing Press. He can help you in your quest for open source tools and libraries, just drop an e-mail to

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories