Getting Started 2
Intro | MinGW with Code::Blocks setup | Your First Program
Adding PDCurses | Adding Allegro
External libraries are the reason why C/C++ remains, after all of its years, current. There is a base level of functions and libraries that come standard with any C/C++ installation, but those do little more than handle basic Input/output and a few cool routines. If you want to really do the cool, state of the art, things that you see in modern games, you’ll need to extend C/C++.
However, it’s not always easy, especially the first time. That’s why I’ve chosen PDCurses. Curses programs are not much bigger than standard C/C++ program, but have the potential to be much cooler. However, PDCurses doesn’t always install easy, so it’s an excellent example of what you may have to go through.
This tutorial assumes you are using Code::Blocks and that you installed it in C:\CodeBlocks as shown in the last tutorial.
Installing PDCurses
First a short video:
From the video the steps are:
- Go to http://pdcurses.sourceforge.net
- On the left click Downloads, click on the Download button next to the latest PDCurses release, then download the .zip file.
- Extract the .zip file to c:\codeblocks\pdcurses and open up the folder.
- Copy and paste the contents of the address bar for later.
- Under the start menu choose Programs->Accessories->Command Prompt
- Type the following being sure to press the right-mouse button and select Paste when it says to:
- Open Code::Blocks.
- Start a new project. Make it a console application.
- Choose C for your language.
- Name your project. I recommend “CursesHello”
- Go to the Management pane, under the Projects tab expand your sources and open main.c.
- Clear out what’s there and paste the following code:
- Before this will compile we need to point the compiler to the library we created earlier.
- In the menu choose Project->Build Options.
- Click on the Linker Settings tab.
- Click the Add button. Point it to c:\codeblocks\pdcurses\win32\pdcurses.a
- In the windows that pops up choose “No” to keeping this a relative path.
- Click on Search Directories tab.
- Add c:\codeblocks\pdcurses and c:\codeblocks\pdcurses\win32 to all three tabs under the Search Directories tab; Compiler, Linker and Resource Compiler.
- Click the OK button.
- Build and run the program.
cd\
cls
set PDCURSES_SRCDIR= (right-mouse click->Paste)
path=c:\codeblocks\mingw\bin
cd (right-mouse click->Paste)
cd win32
mingw32-make -f mingwin32.mak
exit
#include <curses.h>
int main() {
initscr(); /* Start curses mode */
printw("Hello World!"); /* Print Hello World */
refresh(); /* Print it on to the real screen */
getch(); /* Wait for user input */
endwin(); /* End curses mode */
return 0;
}
Congratulations, you’ve just built, installed, and used the external PDCurses library.
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:
- Go to http://www.talula.demon.co.uk/allegro/ and download the latest stable source.
- Extract the .zip file to your MinGW directory (c:\CodeBlocks\MinGW if you’ve followed the tutorials). There should be a new directory under \MinGW created called Allegro
- Download the DirectX package from http://alleg.sourceforge.net/files/dx70_mgw.zip
- Extract dx70_mgw.zip to c:\CodeBlocks\MinGW overwriting all files.
- Under the start menu choose Programs->Accessories->Command Prompt
- Type the following:
PATH=c:\CodeBlocks\MinGW\bin; (if you’ve installed according to the previous instructions or whichever directory your MinGW\bin can be found)
cd\
gcc -v - 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. - Still in the command prompt type:
cd \CodeBlocks\MinGW\Allegro
set MINGDIR=c:\CodeBlocks\MinGW
fix mingw32
mingw32-make (This will be a few minutes)
mingw32-make install’
exit - Now let’s make our first program. Open Code::Blocks.
- Start a new project. Make it a console application.
- Choose C for your language.
- Name your project. I recommend “AllegroHello”
- Go to the Management pane, under the Projects tab expand your sources and open main.c.
- 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 320×200 */
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 mode\n%s\n”, 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() - Like before we need to point the compiler to the allegro library.
- In the menu choose Project->Build Options.
- Click on the Linker Settings tab.
- Click the Add button. Point it to C:\CodeBlocks\MinGW\allegro\lib\mingw32\liballeg.a
- In the windows that pops up choose “No” to keeping this a relative path.
- Click on Search Directories tab.
- Add C:\CodeBlocks\MinGW\allegro\ and C:\CodeBlocks\MinGW\allegro\lib\ to all three tabs under the Search Directories tab; Compiler, Linker and Resource Compiler.
- Click the OK button.
- Build and run the program.
- 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:\CodeBlocks\MinGW\allegro\lib\mingw32 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.
Subscribe
Support Cymon's Games
Recent Comments
- David Brady on Book feedback
- Joe on Happy Thanksgiving
- Mike on Happy Thanksgiving
- Joe on NumbrixGenerator
- Joe on Book feedback
- Craig on Book feedback
- Craig on Numbrix
- Joe on Numbrix















