If you haven't already gotten the DevKit then you need to load up vUpdate. Close down any Dev-C++ you have open and go to where you installed it and run vUpdate.exe. Click the checkmark to get a list of things you can download and hunt for the Allegro DevPak. If its in the list, check it off and hit the checkmark. Just go through the download and install and close up your Package Manager when you're done. Then skip to the next section.
If you can't find the Allegro DevPak in vUpdate then you've already downloaded it. In that case close vUpdate and load Packman.exe from the same place you loaded vUpdate from. If one of the cardboard boxes is labelled Allegro, close the Package Manager and skip to the next section; you're ready to go. If not then you have to install the downloaded package. Click on the Install button at the upper left and hunt down the DevPaks folder in of the folder you installed Dev-C++ to. One of the files will be called Allegro.DevPak, double click on it or click it and then click the Open button to get it started. Finish up the install, close up the Package Manager, and you're done.
I find it far more convenient being able to get at the Allegro Docs through the help menu than I do using explorer to track it down every time. I had a shortcut on my desktop at one time, but I find the Help Menu really is the most convenient place for it. Adding it there is pretty easy. Open Dev-C++, click Help > Customize Help Menu..., and click on the Add button. What you need to do now is hunt the docs down. You'll find them wherever you installed Dev-C++, in a folder Docs/Allegro. You want to choose the allegro.html file so you'll need to show Files of Type: All files (*.*) or HTML files (*.htm;*.html) to see it. Once you've chosen it you're taken back to the Help Menu Editor - click on the new allegro.html item and click the Rename button to choose a better name. I've chosen Allegro Reference. When you're done, click OK and look at the Help Menu to see your new entry. Any time you need a reference to Allegro, its now there in your Help Menu.
Load up Dev-C++ and click File > New > Project... or click the New Project button. If you click the MultiMedia tab, you'll see two different icons for Allegro - one is DLL and the other is Static. Both will make Allegro programs, but each will run a little differently.
If you make an Allegro (DLL) program, you will compile a smaller program, but you will require the alleg40.dll runtime library to be available with your program. If this is what you would like, you can find a distributable alleg40.dll where you installed Dev-C++, in the dll folder. This is the method I prefer, as I use less server space this way. You may need to copy the file to your \windows\system32 folder to run any programs compiled this way - and anyone you distribute to will likely need to do the same.
If you make an Allegro (Static) program, the program will be much bigger in size, but you won't have to worry about distributing alleg40.dll because it will attach itself to the program. I used to do it this way at one time because I didn't like having to download something seperate to run a demo.
Be aware of the difference and choose one. I will pick Allegro (DLL) because its what I normally use. It really doesn't matter what you pick because you program both exactly the same. Make a place for the project and put it there. Once you've done this, a file is made for you already and is actually ready to go. Save it where it wants to put it and go ahead and compile and run the program. The program goes fullscreen and displays some text. Sure, its nothing special, but its a beginning.
#include <allegro.h> int main() { // Initialize Allegro. allegro_init(); // Set the resolution to 640 by 480 with SAFE autodetection. set_gfx_mode(GFX_SAFE, 640, 480, 0, 0); // Installing the keyboard handler. install_keyboard(); // Printing text to the screen. textout(screen, font, "Hello World!", 1, 1, 10); textout(screen, font, "Press ESCape to quit.", 1, 12, 11); // Looping until the ESCape key is pressed. while(! key[KEY_ESC]) poll_keyboard(); // This shouldn't be necessary in Windows. // Exit program. allegro_exit(); return 0; } // Some Allegro magic to deal with WinMain(). END_OF_MAIN(); |
Now that you've run your first Allegro creation, have a look at the code. Notice that you have to #include <allegro.h>. Notice that you never have to worry about WinMain or WndProc - they are taken care of for you. However, note that you MUST have END_OF_MAIN() at the end of your main() function. If you don't have that there you will get a linker error:
[Linker error] undefined reference to `WinMain@16'
There isn't anything left to add to this tutorial - I've walked you through how to download and install the Allegro DevPak and how to make a program that uses Allegro. Don't be shy about it, get right in and get your hands dirty. Experience is the best way to learn stuff. Have fun!