Friday, July 4, 2014

[ALLEGRO] Setup w/ Code::Blocks (Or any other setup)


Introduction

Hey guys, I decided to redo my old Allegro tutorial, seeing as it was pretty outdated. So, let's get started setting up Allegro on Windows with Code::Blocks. :)


Prerequisites

  • Allegro:
    How do you expect to get anything done without this? It's the what the tutorial is for! You can download it here: http://alleg.sourceforge.net/download.html

    Windows users will have to scroll all the way down to the bottom to get the link. Window hate? Not quite, Unix/Linux/Mac users all have to compile it! :twisted:

    (Though, it might be easier to compile it :P)

    We'll assume you're compiling Allegro. Let's continue.
  • Code::Blocks:
    We're using this to set up Allegro with, but if you're macho enough, you can do it with any other setup. Download Code::Blocks here: http://www.codeblocks.org/downloads
  • A working C/C++ compiler
    This is needed to run the "hello world" program. :P

  If you are going to compile the source files

Allegro is divided into a core library and a number of addon libraries.
The core library depends on certain libraries to function. If you don't have
those, nothing will work. These are required for the core library:

- DirectX SDK (Windows only)

You can get this for MSVC from the Microsoft web site (large download).

Alternatively, smaller downloads for MSVC and MinGW are available here:
<http://trent.gamblin.ca/dx/>

Some of those are originally from:
<http://www.g-productions.net/list.php?c=files_devpak>

- X11 development libraries (Linux/Unix only)
The libraries will be part of your Linux distribution, but you may have to
install them explicitly.

- OpenGL development libraries (optional only on Windows)

The addons, too, may require additional libraries. Since the addons are
strictly optional, they are not required to build Allegro, but a lot of
functionality may be disabled if they are not present.

Windows users may find some precompiled binaries for the additional libraries
from <http://gnuwin32.sourceforge.net/>. You need to get the `bin` and `lib`
packages. The `bin` packages contain DLLs, and the `lib` packages contain the
headers and import libraries.

Mac users may find some dependencies in Fink or MacPorts.
<http://www.finkproject.org/> and <http://www.macports.org/>

Linux users likely have all the dependencies already, except PhysicsFS
and DUMB. If your distribution uses separate development packages, they
will need to be installed. The packages are probably named *-dev or *-devel.

These are the dependencies required for the addons:

- libpng and zlib, for PNG image support (Unix and older MinGW only)
Home page: <http://www.libpng.org/pub/png/>
Windows binaries: <http://gnuwin32.sourceforge.net/packages/libpng.htm>

On Windows/Mac OS X/iPhone, PNG image support is available by using the
native facilities on the respective operating systems, so libpng is not
required.

- libjpeg, for JPEG image support (Unix and older MinGW only)
Home page: <http://www.ijg.org/>
Windows binaries: <http://gnuwin32.sourceforge.net/packages/jpeg.htm>

On Windows/Mac OS X/iPhone, JPEG image support is available by using the
native facilities on the respective operating systems, so libjpeg is not
required.

- FreeType, for TrueType font support.
Home page: <http://freetype.sourceforge.net/>
Windows binaries: <http://gnuwin32.sourceforge.net/packages/freetype.htm>

- Ogg Vorbis, a free lossy audio format. (libogg, libvorbis, libvorbisfile)
Home page: <http://www.vorbis.com/>

- FLAC, a free lossless audio codec. (libFLAC, libogg)
Home page: <http://flac.sourceforge.net/>

- DUMB, an IT, XM, S3M and MOD player library. (libdumb)
Home page: <http://dumb.sourceforge.net/>

- OpenAL, a 3D audio API.
The audio addon can use OpenAL, although the 3D capabilities aren't used.
<http://kcat.strangesoft.net/openal.html>

On Mac OS X, OpenAL is *required* but should come with the OS anyway.

On Linux and Windows, OpenAL will only be used if you request it, hence there
is no reason to install it specifically.

- PhysicsFS, provides access to archives, e.g. .zip files.
Home page: <http://icculus.org/physfs/>

On Windows it may be a pain to place all these libraries such that they can be
found. Please see the README_cmake.txt section on the "deps subdirectory"
when the time comes.

Got that? Let's continue. Windows users can either choose to build it or grab the binaries, get the binaries here to save time: https://www.allegro.cc/forums/

Or here:

http://alleg.sourceforge.net/news.html



Getting Allegro out the box

 

If you are using the binaries

This is so easy! Just extract the download and move the files over in the directory, it even contains a readme to help you! Good luck!


If you are building Allegro

Allegro is stuck inside an archive, we need to get it out pronto if we want any work done. So get it out here and we can start. After you've finished extracting that son-of-a-gun, move into the "allegro" directory inside it. It should be like: allegro-<version> -> allegro

In there, you will see many cryptic files and folders... Don't scream at them! Calm down, and I'll tell you the next step.

You will have to compile Allegro as it is all source code, for convenience, we'll use CMake to help build it all. You can get CMake from here: http://www.cmake.org/

Once you've installed CMake, you should run it so we can begin the compilation. It would be best to read the Readme:

% Allegro 5

Overview
========

Welcome to Allegro 5, a cross-platform game programming library.
Currently supported platforms are Linux/Unix, Windows, MacOS X and iPhone.
Note that Allegro 5 is wholly *incompatible* with Allegro 4 and earlier
versions, but both may be installed at the same time without conflicts.

This readme contains general information which applies to all platforms
that Allegro builds on.

README_cmake.txt discusses some build options for cmake.

README_msvc.txt discusses compilation on Windows with Microsoft Visual C/C++.

README_make.txt discusses compilation with GNU make. This applies to Unix-like
operating systems such as Linux, MacOS X and MinGW on Windows.

README_macosx.txt has a few additional notes for MacOS X.

README_iphone.txt discusses iPhone operating systems.



Requirements
============

We assume you have C and C++ compilers installed and functioning.
We support gcc and MSVC.

Allegro also requires CMake 2.6 or later to build.
You may download it from <http://www.cmake.org/>



Library dependencies
====================

Allegro is divided into a core library and a number of addon libraries.
The core library depends on certain libraries to function. If you don't have
those, nothing will work. These are required for the core library:

- DirectX SDK (Windows only)

You can get this for MSVC from the Microsoft web site (large download).

Alternatively, smaller downloads for MSVC and MinGW are available here:
<http://trent.gamblin.ca/dx/>

Some of those are originally from:
<http://www.g-productions.net/list.php?c=files_devpak>

- X11 development libraries (Linux/Unix only)
The libraries will be part of your Linux distribution, but you may have to
install them explicitly.

- OpenGL development libraries (optional only on Windows)

The addons, too, may require additional libraries. Since the addons are
strictly optional, they are not required to build Allegro, but a lot of
functionality may be disabled if they are not present.

Windows users may find some precompiled binaries for the additional libraries
from <http://gnuwin32.sourceforge.net/>. You need to get the `bin` and `lib`
packages. The `bin` packages contain DLLs, and the `lib` packages contain the
headers and import libraries.

Mac users may find some dependencies in Fink or MacPorts.
<http://www.finkproject.org/> and <http://www.macports.org/>

Linux users likely have all the dependencies already, except PhysicsFS
and DUMB. If your distribution uses separate development packages, they
will need to be installed. The packages are probably named *-dev or *-devel.

These are the dependencies required for the addons:

- libpng and zlib, for PNG image support (Unix and older MinGW only)
Home page: <http://www.libpng.org/pub/png/>
Windows binaries: <http://gnuwin32.sourceforge.net/packages/libpng.htm>

On Windows/Mac OS X/iPhone, PNG image support is available by using the
native facilities on the respective operating systems, so libpng is not
required.

- libjpeg, for JPEG image support (Unix and older MinGW only)
Home page: <http://www.ijg.org/>
Windows binaries: <http://gnuwin32.sourceforge.net/packages/jpeg.htm>

On Windows/Mac OS X/iPhone, JPEG image support is available by using the
native facilities on the respective operating systems, so libjpeg is not
required.

- FreeType, for TrueType font support.
Home page: <http://freetype.sourceforge.net/>
Windows binaries: <http://gnuwin32.sourceforge.net/packages/freetype.htm>

- Ogg Vorbis, a free lossy audio format. (libogg, libvorbis, libvorbisfile)
Home page: <http://www.vorbis.com/>

- FLAC, a free lossless audio codec. (libFLAC, libogg)
Home page: <http://flac.sourceforge.net/>

- DUMB, an IT, XM, S3M and MOD player library. (libdumb)
Home page: <http://dumb.sourceforge.net/>

- OpenAL, a 3D audio API.
The audio addon can use OpenAL, although the 3D capabilities aren't used.
<http://kcat.strangesoft.net/openal.html>

On Mac OS X, OpenAL is *required* but should come with the OS anyway.

On Linux and Windows, OpenAL will only be used if you request it, hence there
is no reason to install it specifically.

- PhysicsFS, provides access to archives, e.g. .zip files.
Home page: <http://icculus.org/physfs/>

On Windows it may be a pain to place all these libraries such that they can be
found. Please see the README_cmake.txt section on the "deps subdirectory"
when the time comes.



API documentation
=================

To build the documentation you will need Pandoc.
Pandoc's home page is <http://johnmacfarlane.net/pandoc/>

Installing Pandoc from source can be challenging, but you can build Allegro
without building the documentation.

Online documentation is available on the Allegro web site:
<http://docs.liballeg.org/>



Building with CMake
===================

Building with CMake is a two step process. During the _configuration_ step,
cmake will detect your compiler setup and find the libraries which are
installed on your system. At the same time, you may select options to
customise your build. If you are unsure of what you are doing, leave all the
options at the defaults.

Once the configuration step is successful, you will invoke another tool to
build Allegro. The tool depends on your compiler, but is usually either
`make`, or your IDE.

To avoid problems, unpack Allegro into a directory *without spaces or other
"weird" characters in the path*. This is a known problem.

Now read README_msvc.txt, README_make.txt or README_macosx.txt.
Including the additional readmes that came with your copy. Just read it all and let it all soak in so we can continue to our next step.

Building Allegro


With CMake open, we have to first find the button that reads, "Browse Source...". We need this to locate our source code we are building, select the "allegro-<version>/allegro" directory to continue. It is the directory that contains CMakelists.txt, which we need in order to build with CMake, do not use the "allegro-<version>/allegro/src" directory. It will not work.

Next, we need to tell CMake where to build everything. I would just make a folder called "build" in the "allegro-<version>/allegro" directory. Build it there.

Next, choose configure. Here, you will have to choose your set up. Mine is "CodeBocks - MinGW Makefiles" and I specified the native custom MinGW compiler I have in another directory. Be sure to choose the correct set up!

Now just wait for it to configure... Done!

It's not unlikely that CMake failed the first time, read the error and try to make sense of it. For example, mine say it failed because:

Could NOT find DINPUT (missing:  DINPUT_INCLUDE_DIR) 
CMake Error at CMakeLists.txt:620 (message):
Windows port requires DirectInput (not found).
 
This of course means we don't have the Direct X libraries installed, or CMake can't find them. For me, it's the latter case.
Allegro readme wrote:You can get this for MSVC from the Microsoft web site (large download).

Alternatively, smaller downloads for MSVC and MinGW are available here:
<http://trent.gamblin.ca/dx/>

Some of those are originally from:
<http://www.g-productions.net/list.php?c=files_devpak>


So I tried to download the SDK from those links... both were down. I can't download the Direct X SDK from microsoft, it's HUGE. So instead, I googled and found this: http://alleg.sourceforge.net/wip.html

At the bottom of the page it reads:
dx70_mgw.zip - 243k - This file contains the minimal version of the DirectX 7 SDK for MinGW. Only for Windows.


243 kibibytes is awesome. :)

Download that, extract it, and then copy and paste the "include" and "lib" directories to overwrite their counterparts in the compilers directory. Just to be safe, don't overwrite any files.

Now, be sure to start over by deleting your Cache (File -> Delete Cache), you'll be able to click configure again to try once more.

---

Seems I still have errors:
 
Could NOT find D3DX9 (missing:  D3DX9_INCLUDE_DIR D3DX9_LIBRARY) 
Could NOT find FLAC (missing:  OGG_LIBRARY FLAC_LIBRARY) 
WARNING: libFLAC not found or compile test failed, disabling support.
Could NOT find DUMB (missing:  DUMB_LIBRARY) 
WARNING: libdumb not found or compile test failed, disabling support. <http://dumb.sourceforge.net/>
Could NOT find OGG (missing:  OGG_LIBRARY) 
WARNING: libvorbis not found or compile test failed, disabling support.
Could NOT find Freetype (missing:  FREETYPE_LIBRARY) 
WARNING: FreeType not found, disabling support.
Could NOT find PhysFS (missing:  PHYSFS_LIBRARY) 
Could NOT find PHYSFS (missing:  PHYSFS_LIBRARY) 
 
That means, we did not get the dependencies the Readme told us to get. So get them now and we can continue. Now that this is done, we can hit the "Generate" button to generate a Code::Blocks project. Open it up and Code::Blocks, select which build target to build, and hit build. Now wait as it compiles... After it is done, install it. You can copy and paste files or use some other method. Proceed to the next portion of the tutorial.  

Setting up Allegro for use


Now, let's start up Code::Blocks and hit the "File" item in the top left of the window. Then, go to New -> Project. A new menu will jump up at ya. Select "Console Application" from that list then, hit "Go". You'll be presented with a Wizard that I'll guide you all through, cause I'm so brave.

1. Hit "Next>".

2. Select C++.

Project title: Allegro 5
Folder to create project in: C:\

3. Enter the information as stated above. (The rest is filled in automatically)
Hit "Next>".

4. Hit "Finish".

Now, we should be back at where we were. Copy and Paste (Don't make copying and pasting code a habit! ) this code here:

#include <allegro5/allegro.h>

int main(){
   al_init();
   al_init_font_addon();
   al_init_ttf_addon();
   ALLEGRO_DISPLAY *display = al_create_display( 640, 480 );
   al_clear_to_color( al_map_rgb( 0, 0, 0 ) );
   al_flip_display();
   al_rest( 10.0 );
   al_destroy_display( display );
   return 0;
}


Remember to save!

Compile the program and run it to test it out. ;)

If anything goes awry, read this tutorial here for clarification: http://wiki.allegro.cc/index.php?title= ... _Allegro_5

Note :This tutorial has been written by waratte, all credit goes to him for spending time on writing this so that we could learn and like he says "Spread the knowledge!" :)

You can read the original tutorial here: http://bb.waratteka.net/viewtopic.php?f=14&t=137

Widgets

 

Copyright @ 2014 CPP Fuzz.