Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Installing Allegro 5.0.0 RC4 with Code::Blocks and MingW on Windows XP/7

This thread is locked; no one can reply to it. rss feed Print
Installing Allegro 5.0.0 RC4 with Code::Blocks and MingW on Windows XP/7
DocHoliday
Member #12,498
January 2011

I figured that I would save some people some time when trying to install Allegro 5 with code::blocks. I wrote this guide really fast, so let me know if you have any questions or need clarification. BTW, I just found out that the syntax is different for version 5, and i just threw on the first working example that I could find,
which is located at,
http://wiki.allegro.cc/index.php?title=Allegro_5_Tutorial/Bitmaps.

Installing Allegro 5.0.0 RC4 with Code::Blocks and MingW on Windows XP/7

1. Download "codeblocks-10.05mingw-setup.exe" located at:
http://sourceforge.net/projects/codeblocks/files/Binaries/10.05/Windows/codeblocks-10.05mingw-setup.exe/download

2. Download "dx9mgw.zip" located at:
http://trent.gamblin.ca/dx/dx9mgw.zip

3.Download "cmake-2.8.3-win32-x86.exe" located at:
http://www.cmake.org/files/v2.8/cmake-2.8.3-win32-x86.exe

4. Download "allegro-5.0.0rc4.7z" located at:
http://sourceforge.net/projects/alleg/files/allegro-prerelease/5.0.0-rc4/allegro-5.0.0rc4.7z/download

5. Install the "codeblocks-10.05mingw-setup.exe" From step 1
into the directory C:\codeblocks. Select whichever, "contrib plugins" that you would like to install. Choose to Finish without running codeblocks.

6. Add this Environment Variable to the end of the "path" system variable: ;C:\codeblocks\mingw\bin; (make sure that a semi-colon precedes the name, as shown)

7. Make a new Environment Variable, a System Variable, named MINGDIR, and give it the value: C:\codeblocks\mingw.

8. Extract "dx9mgw.zip" to "dx9mgw" and copy the "lib" and "include" folders located inside of "dx9mgw" directly to C:\codeblocks\mingw.
Choose "Yes to All" when asked about overwriting anything in the old "lib" and "include".

9. Extract "allegro-5.0.0rc4.7z" to "allegro-5.0.0rc4", enter the directory and click until you see
a folder named "allegro". Copy "allegro" to the "C:\codeblocks\mingw" directory.

10. Install "cmake-2.8.3-win32-x86.exe" to "C:\cmake" and be sure to select the option to "Add CMAKE to the system path for the current user". This is not the default.

11. Navigate to "C:\codeblocks\mingw\allegro" and create a new folder named "build".

12. Go to Start and type cmd to run the terminal window.
-type "c:" without quotes and press enter
-type "cd C:\codeblocks\mingw\allegro\build" without quotes and press enter
-type (cmake .. -G "MinGW Makefiles") without parantheticals and press enter
wait for this to complete without errors. Some "Not Found" and "Failed" messages should be okay.
They appear because it didn't find additional libraries that are not required.
-type "mingw32-make" without quotes and press enter
this could take a while to fully complete.
-type "mingw32-make install" without quotes and press enter
-type "exit" without quotes and press enter

13. Run the Code::Blocks program for the first time.
-Click Settings->Compiler And Debugger->Toolchain executables. Click Auto-Detect for the compilers installation directory.
A message should appear saying, (Auto-detected installation path of "GNU GCC Compiler" in "C:\codeblocks\mingw"). Click OK. Click OK again.

14. Click File->New Project->Win32GUIProject. Click Next. Select "Frame Based" and click next. Name your project and put it in its own folder. Click Next.
Check that the GNU GCC compiler is selected, leave the other options checked for debug and release and click Finish.

15. Press F9 to run the window code if you want to.

16. Delete all of the code and enter the code below:

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3 4const float FPS = 60; 5const int SCREEN_W = 640; 6const int SCREEN_H = 480; 7const int BOUNCER_SIZE = 32; 8 9int main(int argc, char **argv) 10{ 11 ALLEGRO_DISPLAY *display = NULL; 12 ALLEGRO_EVENT_QUEUE *event_queue = NULL; 13 ALLEGRO_TIMER *timer = NULL; 14 ALLEGRO_BITMAP *bouncer = NULL; 15 float bouncer_x = SCREEN_W / 2.0 - BOUNCER_SIZE / 2.0; 16 float bouncer_y = SCREEN_H / 2.0 - BOUNCER_SIZE / 2.0; 17 float bouncer_dx = -4.0, bouncer_dy = 4.0; 18 bool redraw = true; 19 20 if(!al_init()) { 21 fprintf(stderr, "failed to initialize allegro!\n"); 22 return -1; 23 } 24 25 timer = al_create_timer(1.0 / FPS); 26 if(!timer) { 27 fprintf(stderr, "failed to create timer!\n"); 28 return -1; 29 } 30 31 display = al_create_display(SCREEN_W, SCREEN_H); 32 if(!display) { 33 fprintf(stderr, "failed to create display!\n"); 34 al_destroy_timer(timer); 35 return -1; 36 } 37 38 bouncer = al_create_bitmap(BOUNCER_SIZE, BOUNCER_SIZE); 39 if(!bouncer) { 40 fprintf(stderr, "failed to create bouncer bitmap!\n"); 41 al_destroy_display(display); 42 al_destroy_timer(timer); 43 return -1; 44 } 45 46 al_set_target_bitmap(bouncer); 47 48 al_clear_to_color(al_map_rgb(255, 0, 255)); 49 50 al_set_target_bitmap(al_get_backbuffer(display)); 51 52 event_queue = al_create_event_queue(); 53 if(!event_queue) { 54 fprintf(stderr, "failed to create event_queue!\n"); 55 al_destroy_bitmap(bouncer); 56 al_destroy_display(display); 57 al_destroy_timer(timer); 58 return -1; 59 } 60 61 al_register_event_source(event_queue, al_get_display_event_source(display)); 62 63 al_register_event_source(event_queue, al_get_timer_event_source(timer)); 64 65 al_clear_to_color(al_map_rgb(0,0,0)); 66 67 al_flip_display(); 68 69 al_start_timer(timer); 70 71 while(1) 72 { 73 ALLEGRO_EVENT ev; 74 al_wait_for_event(event_queue, &ev); 75 76 if(ev.type == ALLEGRO_EVENT_TIMER) { 77 if(bouncer_x < 0 || bouncer_x > SCREEN_W - BOUNCER_SIZE) { 78 bouncer_dx = -bouncer_dx; 79 } 80 81 if(bouncer_y < 0 || bouncer_y > SCREEN_H - BOUNCER_SIZE) { 82 bouncer_dy = -bouncer_dy; 83 } 84 85 bouncer_x += bouncer_dx; 86 bouncer_y += bouncer_dy; 87 88 redraw = true; 89 } 90 else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { 91 break; 92 } 93 94 if(redraw && al_is_event_queue_empty(event_queue)) { 95 redraw = false; 96 97 al_clear_to_color(al_map_rgb(0,0,0)); 98 99 al_draw_bitmap(bouncer, bouncer_x, bouncer_y, 0); 100 101 al_flip_display(); 102 } 103 } 104 105 al_destroy_bitmap(bouncer); 106 al_destroy_timer(timer); 107 al_destroy_display(display); 108 al_destroy_event_queue(event_queue); 109 110 return 0; 111}

17. This won't compile just yet. MAke sure to include the allegro library files as shown below:
Click Project->Build Options->Linker Settings. Click Add. Click the "..." box.
Navigate to "C:\codeblocks\MinGW\lib" and select "liballegro.dll.a".
Keep the path as relative, or not, it depends on what you prefer if the locations of the file changes in the future.

18. Build,Compile, and run the code to see if everything installed correctly.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

This looks like a pretty good guide. You should put it up on the Allegro wiki.

Don't forget to use <code></code> tags for posting code. You can edit your post to fix this by clicking on the edit post button near the top of your post.

Go to: