Graphics Programming using Allegro

Installation and Testing

Published:  August 22, 2008
Revised:  August 23, 2008
by Richard G. Baldwin

File:  Allegro00105


 

Preface

General

This is the first lesson in a series designed to teach you how to use Allegro to do graphics programming in C++.  My purpose in writing the series is to provide lecture and lab material for a course titled Game Development Using C++ that I teach at Austin Community College in Austin, Texas.  However, if you have stumbled upon this series and you find it useful, you are welcome to study it.

Viewing tip

I recommend that you open another copy of this document in a separate browser window and use the following links to easily find and view the figures and listings while you are reading about them.

Figures

Listings

Supplemental material

I recommend that you also study the other lessons in my extensive collection of online programming tutorials.  You will find a consolidated index at www.DickBaldwin.com.

General background information

According to the Allegro website (see Resources),

"Allegro is a game programming library for C/C++ developers distributed freely, supporting the following platforms: DOS, Unix (Linux, FreeBSD, Irix, Solaris, Darwin), Windows, QNX, BeOS and MacOS X. It provides many functions for graphics, sounds, player input (keyboard, mouse and joystick) and timers. It also provides fixed and floating point mathematical functions, 3d functions, file management functions, compressed datafile and a GUI."

Allegro is freely available

One of the first things that interests me about Allegro is that it is free.  Thus, my students can download and run it on their computers at home without having to pay for it.

Compatibility with Dev-C++

Another of my interests in using Allegro for the course is compatibility with the BloodshedSoftware Dev-C++ IDE (see Resources), which is also free for my students to download and install on their computers at home.  Even though the computers in the lab where I teach are configured with the Windows XP operating system, my preference is to avoid using a graphics library that requires the use of Microsoft Visual Studio.

Extensive capability

A third thing that attracts me to Allegro for this course is that it has more capability than we can possibly cover in a single one-semester course.  Therefore, given that it is freely available and compatible with a free C++ IDE, my students can continue to develop their graphics programming skills long after they finish my course of instruction.

Preview

This document provides instructions for downloading Allegro and installing it in the library of an existing BloodshedSoftware Dev-C++ installation (see Resources).

The installation and test procedure described herein was gleaned from http://www.gamedev.net/community/forums/topic.asp?topic_id=354954 and confirmed to work for Windows XP Professional and also for Windows Vista Home Premium Edition.

Software installation

Fortunately, downloading and installing the Allegro software for an existing Dev-C++ installation is straightforward.  Just click here and follow the prompts.  When the installation is complete, the Allegro library material will have been deposited in the Dev-Cpp\lib folder of the existing Dev-C++ installation.

Software testing

To create an Allegro/Dev-C++ project that can be used to test the Allegro installation, do the following:

Listing 1. Code for testing Allegro installation.
#include "allegro.h"
int main(){
  allegro_init();
  allegro_message("Hello World!");
  return 0;
}
END_OF_MAIN();

The correct result

If all goes well, a dialog similar to that shown in Figure 1 should appear on your screen.  If you click the OK button on the dialog, the dialog will disappear from the screen.

Figure 1. Screen output from initial test.

Contents of the project folder

At this point, the project folder should contain one file each with the extensions:

The names of the files will depend on the names that you specified earlier, except that the last file in the above list will be named Makefile.win (assuming that you are installing and testing under a Windows operating system).

Unable to execute the exe file directly

Ideally, at this point, you should be able to double-click the exe file to execute the program.  However, as of this writing, I am unable to do so under Windows Vista with an error message that reads "This application has failed to start because alleg42.dll was not found.  Re-installing the application may fix this problem."

The file named alleg42.dll is in the bin folder of the Dev-C++ installation.  I was able to solve the problem by copying it into the directory with the exe file, which is not an ideal solution.  I was also able to solve the problem by putting the bin folder of the Dev-C++ installation on the path.  That is a better solution.

A template for future projects

You can use this project as a template for future projects and avoid having to go through the steps listed above.  Copy the entire project folder that you have just created and give it a different name.  Then open the dev file contained in that folder in the Dev-C++ IDE. 

How do you open the project in Dev-C++?

Depending on how you have Windows configured, you may be able to simply double click on the dev file to cause it to open in Dev-C++.  If not, you can start Dev-C++ and select Open Project or File in the File menu to open the new project.

Updating the project

Following that, you can use the features of the Dev-C++ IDE to modify and expand the project to meet your needs.  For example, if the necessary files already exist in the new project folder, select Project/Add to Project and add the files to the project.

If a necessary file doesn't already exist in the project folder, select File/New/Source File to add a new file named Untitled1 to the project.  Right-click and rename the file in the tree on the left.  Then create the source code for the new file in the editor.

Summary

This document provides instructions for downloading Allegro and installing it in the library of an existing BloodshedSoftware Dev-C++ installation (see Resources).

Resources


Copyright

Copyright 2008, Richard G. Baldwin.  Reproduction in whole or in part in any form or medium without express written permission from Richard Baldwin is prohibited.

About the author

Richard Baldwin is a college professor (at Austin Community College in Austin, TX) and private consultant whose primary focus is a combination of Java, C#, and XML. In addition to the many platform and/or language independent benefits of Java and C# applications, he believes that a combination of Java, C#, and XML will become the primary driving force in the delivery of structured information on the Web.

Richard has participated in numerous consulting projects and he frequently provides onsite training at the high-tech companies located in and around Austin, Texas.  He is the author of Baldwin's Programming Tutorials, which have gained a worldwide following among experienced and aspiring programmers. He has also published articles in JavaPro magazine.

In addition to his programming expertise, Richard has many years of practical experience in Digital Signal Processing (DSP).  His first job after he earned his Bachelor's degree was doing DSP in the Seismic Research Department of Texas Instruments.  (TI is still a world leader in DSP.)  In the following years, he applied his programming and DSP expertise to other interesting areas including sonar and underwater acoustics.

Richard holds an MSEE degree from Southern Methodist University and has many years of experience in the application of computer technology to real-world problems.

Baldwin@DickBaldwin.com

-end-