The Allegro Wiki is migrating to github at https://github.com/liballeg/allegro_wiki/wiki

Install Allegro 4.9.x Binary for MSVC 2008 Express

From Allegro Wiki
Revision as of 02:49, February 27, 2010 by Tomoso (talk | contribs) (Step 3 - Project Properties)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Installing Allegro 4.9.x for MS Visual C++ 2008 Express

Brief step by step guide on how to get Allegro 4.9.x up and running using MS Visual C++ 2008 Express.


Step 1 - Files Needed

Head over to [www.allegro5.org] and download the latest MSVC Binaries (for this guide I downloaded allegro-4.9.15.1-msvc-bin.7z). Once the download is complete, create a folder on your C:\ drive called "Allegro". Change the name to include version if you like, but for this guide I'll just be using "C:\Allegro". Drag the folders from the zip file into your new "C:\Allegro" directory (in my case dlls\include\lib folders).

Of course you will need Microsoft Visual C++ 2008 Express which you can get from here.

Once we get everything set up, I used this tutorial to make sure it was working correctly. The full source can be found below, and you can either search and download times.ttf from some where or just use another font already on your system.


Step 2 - Creating the Project

Once MSVC++ is installed and ready to go, open it up and create a new Win32 Project. When the application wizard pops up make sure your settings are like those within the picture below.

Install allegro5 binary msvc app settings.PNG


Step 3 - Project Properties

Before we add any code we need to let MSVC++ know about where to find the files for Allegro. Open the project properties window (Project > Properties or Alt+F7).

  1. At the top of the window change Configuration: from Active:(Debug) to All Configurations. This is so we keep the settings we're about to change for all builds of the program.

    Install allegro5 binary msvc proj props 1.PNG

  2. Under Configuration Properties > C\C++ > General add "C:\Allegro\include" to Additional Include Directories. NOTE: If you cannot see this tab in the list, first create a source file, any .cpp file will do. Select it in the project manager, and then retry this step.

    Install allegro5 binary msvc proj props 2.PNG

  3. Under Configuration Properties > Linker > General add "C:\Allegro\lib" to Additional Library Directories.

    Install allegro5 binary msvc proj props 3.PNG

  4. Under Configuration Properties > Linker > Input add "allegro-4.9.15.lib allegro_font-4.9.15.lib allegro_ttf-4.9.15.lib" to Additional Dependencies. (Depending on what your doing within your program you may have to add additional dependencies, for this guide this is all we need).

    Install allegro5 binary msvc proj props 4.PNG


That's all there is to it as far as editing the project settings. Now to test if everything is working.

Step 4 - The Code

Create a new file in your project called "main.cpp" and copy in the code below.

<highlightSyntax language="c">

  1. include <allegro/allegro5.h>
  2. include <allegro/allegro_font.h>
  3. include <allegro/allegro_ttf.h>
  4. include <stdio.h>

int main(int argc, char* args[]) {

 struct Data {
   ALLEGRO_FONT *f1, *f2;
   ALLEGRO_DISPLAY *display;
   ALLEGRO_EVENT_QUEUE *queue;

   ALLEGRO_COLOR bright_green;
 } data;
 const char *font_file = "times.ttf";
 al_init();
 al_init_font_addon();
 data.display = al_create_display(640, 480);
 if(!data.display) {
   printf("Error creating display.\n");
   return 1;
 }
 if(!al_install_keyboard()) {
   printf("Error installing keyboard.\n");
   return 2;
 }
 data.f1 = al_load_ttf_font(font_file, 48, 0);
 data.f2 = al_load_ttf_font(font_file, -48, 0);
 if(!data.f1 || !data.f2) {
   printf("Error loading \"%s\".\n", font_file);
   return 3;
 }
 data.bright_green = al_map_rgba_f(0.5, 1.0, 0.5, 1.0);
 al_set_blender(ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, data.bright_green);
 al_draw_text(data.f1, 10, 10, ALLEGRO_ALIGN_LEFT, "Allegro 5 Rocks!");
 al_draw_text(data.f2, 10, 60, ALLEGRO_ALIGN_LEFT, "Allegro 5 Rocks!");
 al_flip_display();
 data.queue = al_create_event_queue();
 al_register_event_source(data.queue, (ALLEGRO_EVENT_SOURCE*)al_get_keyboard_event_source());
 ALLEGRO_EVENT event;
 while(1) {
   al_wait_for_event(data.queue, &event);
   if(event.type == ALLEGRO_EVENT_KEY_DOWN && event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) 
     break;
 }
 return 0;

}END_OF_MAIN() </highlightSyntax>

As I said before this code is taken from the nice tutorial linked at the begining of this guide, so if you would like an explanation of what's happening head over there.


Step 5 - Compiling

Before you try to compile we still need to move some files about. Open up your project folder (Default location is something like this: "C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects").

Once you have your projects folder open you will want to copy over the font file times.tff. Open up the "\Debug" folder inside your project folder and re-copy the font there also (For some reason if you compile inside MSVC without having the font file in your project folder, it wont find it in the folder where your .exe is so keep it in both for now).

You will also need copy the contents of "C:\Allegro\dll" folder to your "\Debug" folder. You don't need the dlls your not using but better to be safe than sorry.

Now hit compile and hopefully a black window should appear with 2 lines of texts saying "Allegro 5 Rocks!". And that's it, Allegro should now be working in MSVC++ Express 2008.