ovine by design title

RETRO REMAKES AND CLASSIC GAMES *

C/C++ Development

Developing in C/C++ can be done with many compilers, IDE’s and libraries but with so many to choose from where do you start?

Our friends at Cymon’s Games recommend MinGW with Code::Blocks for the compiler and IDE and Allegro for the library (things that will help making games).  Here are some extract from Cymon’s site, please pay him a visit for the complete article and more!  Cymon has also posted a helpful video on You Tube.

 

To install Code::Blocks:

  1. Go to http://www.codeblocks.org, click on downloads then download the latest binary release with MinGW.
  2. Run the downloaded package.
  3. Click Next then click I Agree.
  4. On the next screen you can choose optional packages to install. Which ones you pick are up to you. Click Next when ready.
  5. Remove the “Program Files\” from the install directory and leave just “C:\CodeBlocks”
  6. Click Install and wait for the installation to finish.
  7. When the installation is run Code::Blocks.

Once MinGW and Code::Blocks is install you’re ready to start programming. It is best practice to always use a project so to finish of we’ll start you on your first project.

video where the instructions left off:

  1. Click File->New->Project.
  2. Select the Console Application button. Press Next.
  3. Fill out the fields like so:
    • Project Name: Hello
    • Folder to Create Project in: Select your “My Documents” directory or a specific subdirectory of your choosing.
  4. Press Next. Don’t worry about any of the settings you’re now looking at for the moment and press Next again.
  5. Make sure you’ve selected the appropriate language (C in this case) and press Next.
  6. In the window on the left expand the Sources branch and double-click on the main.c file.
  7. In the main window is where you will type your programs. There is a default “hello world” program there already that you can use.
  8. When you are ready press the build and run button to run your first program

Installing Allegro

If you’ve installed PDCurses chances are you can simply use the allegro wiki and figure out it out. But for those who need a little more help here’s a step-by-step:

  1. Go to http://www.talula.demon.co.uk/allegro/ and download the latest stable source.
  2. Extract the .zip file to your MinGW directory (c:CodeBlocksMinGW if you’ve followed the tutorials). There should be a new directory under MinGW created called Allegro
  3. Download the DirectX package from http://alleg.sourceforge.net/files/dx70_mgw.zip
  4. Extract dx70_mgw.zip to c:CodeBlocksMinGW overwriting all files.
  5. Under the start menu choose Programs->Accessories->Command Prompt
  6. Type the following: PATH=c:CodeBlocksMinGWbin; (if you’ve installed according to the previous instructions or whichever directory your MinGWbin can be found) cd gcc -v
  7. If you’ve done everything properly you should see a message like this: Reading specs from c:/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/specs Configured with: ../gcc-3.4.5/configure –with-gcc –with-gnu-ld –with-gnu-as –host=mingw32 –target=mingw32 –prefix=/mingw –enable-threads –disable-nls –enable-languages=c,c++,f77,ada,objc,java –disable-win32-registry –disable-shared –enable-sjlj-exceptions –enable-libgcj –disable-java-awt –without-x –enable-java-gc=boehm –disable-libgcj-debug –enable-interpreter –enable-hash-synchronization –enable-libstdcxx-debug Thread model: win32 gcc version 3.4.5 (mingw-vista special) If not you’ll see: 'gcc' is not recognized as an internal or external command, operable program or batch file. And you’ll need to try setting the path again making sure you’ve got the right directory.
  8. Still in the command prompt type: cd CodeBlocksMinGWAllegro set MINGDIR=c:CodeBlocksMinGW fix mingw32 mingw32-make (This will be a few minutes) mingw32-make install exit
  9. Now let’s make our first program. Open Code::Blocks.
  10. Start a new project. Make it a console application.
  11. Choose C for your language.
  12. Name your project. I recommend “AllegroHello”
  13. Go to the Management pane, under the Projects tab expand your sources and open main.c.
  14. Clear out what’s there and paste the following code (from http://wiki.allegro.cc/index.php?title=Example_ExHello):
    #include <allegro.h>
    int main(void) {
    /* you should always do this at the start of Allegro programs */
    if (allegro_init() != 0) return 1;
    install_keyboard(); /* set up the keyboard handler */
    /* set a graphics mode sized 320x200 */
    if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) {
    if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
    set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
    allegro_message("Unable to set any graphic moden%s", allegro_error); return 1;
    }
    }
    set_palette(desktop_palette); /* set the color palette */
    clear_to_color(screen, makecol(255, 255, 255)); /* clear the screen to white */
    /* you don't need to do this, but on some platforms (eg. Windows) things
    * will be drawn more quickly if you always acquire the screen before * trying to draw onto it. */
    acquire_screen();
    /* write some text to the screen with black letters and transparent background */
    textout_centre_ex(screen, font, "Hello, world!", SCREEN_W/2, SCREEN_H/2, makecol(0,0,0), -1);
    /* you must always release bitmaps before calling any input functions */
    release_screen();
    readkey(); /* wait for a keypress */
    return 0;
    }
    END_OF_MAIN()
  15. Like before we need to point the compiler to the allegro library.
  16. In the menu choose Project->Build Options.
  17. Click on the Linker Settings tab.
  18. Click the Add button. Point it to C:CodeBlocksMinGWallegrolibmingw32liballeg.a
  19. In the windows that pops up choose “No” to keeping this a relative path.
  20. Click on Search Directories tab.
  21. Add C:CodeBlocksMinGWallegro and C:CodeBlocksMinGWallegrolib to all three tabs under the Search Directories tab; Compiler, Linker and Resource Compiler.
  22. Click the OK button.
  23. Build and run the program.
  24. If everything works up to this point but you’re having trouble running your programs it’s because you’re missing alleg42.dll. All you have to do is find it in C:CodeBlocksMinGWallegrolibmingw32 and copy it to the directory where your .exe is.

At this point you may become aware that our hello world programs are getting bigger. Get used to it. The cooler they get, the bigger they get.