bindbc-allegro5 ~master

Dynamic and static bindings to Allegro and its addons, compatible with -betterC, @nogc, and nothrow.


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

bindbc-allegro5

Note This is not an official BindBC package.

This project provides both static and dynamic bindings to the Allegro libraries. They are compatible with @nogc and nothrow and can be compiled with BetterC compatibility.

Basic Usage

The default configuration generates dynamic bindings to core Allegro v5.2.0 without BetterC compatibility. Dynamic binding assume run-time dynamic linking.

When using run-time dynamic linking, there are no link-time dependencies, but the shared libraries (.dll/.so/.dylib depending on platform) must be present on the user’s machine, and you need to load the libraries and bind to their symbols before use. This is done by calling loadAllegro and the respective functions from the addon submodules.

To target a newer version of Allegro, pass the respective version ID from the supported version list, and to enable addons, pass the respective version IDs from the addon list.

An example that’s configured to use Allegro v5.2.3 with Font and TTF addons:

dub.json

{
    "name": "example",
    "dependencies": {
        "bindbc-allegro5": "~>1.0.0",
    },
    "versions": [
        "Allegro_5_2_3",
        "Allegro_Font",
        "Allegro_TTF"
    ]
}

app.d

import bindbc.allegro5;
import bindbc.allegro5.allegro_font;
import bindbc.allegro5.allegro_ttf;

void main() {
    {
        AllegroSupport ret = loadAllegro();
        assert(ret < allegroSupport, "Error loading Allegro");
    }
    {
        AllegroSupport ret = loadAllegroFont();
        assert(ret < allegroSupport, "Error loading Allegro Font addon");
    }
    {
        AllegroSupport ret = loadAllegroTTF();
        assert(ret < allegroSupport, "Error loading Allegro TTF addon");
    }

    al_init();

    /* Your awesome game */

    al_uninstall_system();
}

AllegroSupport is a enumeration of noLibrary, badLibrary, and values from the from the supported version list. allegroSupport is a manifest constant equal to the target Allegro version (v5_2_3 in our case). loadAllegro will return version number on success or noLibrary/ badLibrary on failure. The version number may be lower than allegroSupport, indicating that the older version was loaded. This example just asserts that the libraries are loaded properly and are no older than v5.2.3, but in the real code you should show a proper error message if the libraries are not found or not compatible. See bindbc-loader error reporting API.

Supported Versions

VersionVersion IDAllegroSupport
5.2.0defaultv5_2_0
5.2.1Allegro_5_2_1v5_2_1
5.2.2Allegro_5_2_2v5_2_2
5.2.3Allegro_5_2_3v5_2_3
5.2.4Allegro_5_2_4v5_2_4
5.2.5Allegro_5_2_5v5_2_5
5.2.6Allegro_5_2_6v5_2_6
5.2.7Allegro_5_2_7v5_2_7
5.2.8Allegro_5_2_8v5_2_8
5.2.9Allegro_5_2_9v5_2_9
5.2.10Allegro_5_2_10v5_2_10

Note: Parts of Allegro API, including most of the new functions introduced in 5.2.x releases, are marked as unstable. If you want to enable unstable API, pass the ALLEGRO_UNSTABLE version. Unstable API is tied to a specific release; e.g. if ALLEGRO_UNSTABLE and Allegro_5_2_3 are passed but the user happen to have Allegro v5.2.4 or newer, the system will fail to initialize.

Addons

AddonVersion IDSubmodule
ImageAllegro_Imageallegro_image
PrimitivesAllegro_Primitivesallegro_primitives
ColorAllegro_Colorallegro_color
FontAllegro_Fontallegro_font
TTF (requires Font addon)Allegro_TTFallegro_ttf
AudioAllegro_Audioallegro_audio
Audio Codec (requires Audio addon)Allegro_ACodecallegro_acodec
Video (requires Audio addon)Allegro_Videoallegro_video
MemfileAllegro_Memfileallegro_memfile
PhysicsFSAllegro_PhysFSallegro_physfs
Native DialogsAllegro_Dialogallegro_native_dialog

Official addons are part of the Allegro package, so they don’t have their own versioning.

Allegro can be built with all addons included. This is called monolith build. To bind to it, pass Allegro_Monolith version. With dynamic bindings, loadAllegro will also bind to all addon functions. You don’t need to call addon loading functions such as loadAllegroImage (they are not even defined in the monolith version).

Dynamic Bindings API

AllegroSupport loadAllegro();
AllegroSupport loadAllegro(const(char)* libName);
void unloadAllegro();
bool isAllegroLoaded();
AllegroSupport loadedAllegroVersion();

Image addon:

AllegroSupport loadAllegroImage();
AllegroSupport loadAllegroImage(const(char)* libName);
void unloadAllegroImage();
bool isAllegroImageLoaded();
AllegroSupport loadedAllegroImageVersion();

Primitives addon:

AllegroSupport loadAllegroPrimitives();
AllegroSupport loadAllegroPrimitives(const(char)* libName);
void unloadAllegroPrimitives();
bool isAllegroPrimitivesLoaded();
AllegroSupport loadedAllegroPrimitivesVersion();

Color addon:

AllegroSupport loadAllegroColor();
AllegroSupport loadAllegroColor(const(char)* libName);
void unloadAllegroColor();
bool isAllegroColorLoaded();
AllegroSupport loadedAllegroColorVersion();

Font addon:

AllegroSupport loadAllegroFont();
AllegroSupport loadAllegroFont(const(char)* libName);
void unloadAllegroFont();
bool isAllegroFontLoaded();
AllegroSupport loadedAllegroFontVersion();

TTF addon:

AllegroSupport loadAllegroTTF();
AllegroSupport loadAllegroTTF(const(char)* libName);
void unloadAllegroTTF();
bool isAllegroTTFLoaded();
AllegroSupport loadedAllegroTTFVersion();

Audio addon:

AllegroSupport loadAllegroAudio();
AllegroSupport loadAllegroAudio(const(char)* libName);
void unloadAllegroAudio();
bool isAllegroAudioLoaded();
AllegroSupport loadedAllegroAudioVersion();

Audio Codec addon:

AllegroSupport loadAllegroACodec();
AllegroSupport loadAllegroACodec(const(char)* libName);
void unloadAllegroACodec();
bool isAllegroACodecLoaded();
AllegroSupport loadedAllegroACodecVersion();

Video addon:

AllegroSupport loadAllegroVideo();
AllegroSupport loadAllegroVideo(const(char)* libName);
void unloadVideoAllegro();
bool isAllegroVideoLoaded();
AllegroSupport loadedAllegroVideoVersion();

Memfile addon:

AllegroSupport loadAllegroMemfile();
AllegroSupport loadAllegroMemfile(const(char)* libName);
void unloadAllegroMemfile();
bool isAllegroMemfileLoaded();
AllegroSupport loadedAllegroMemfileVersion();

PhysicsFS addon:

AllegroSupport loadAllegroPhysFS();
AllegroSupport loadAllegroPhysFS(const(char)* libName);
void unloadAllegroPhysFS();
bool isAllegroPhysFSLoaded();
AllegroSupport loadedAllegroPhysFSVersion();

Native Dialogs addon:

AllegroSupport loadAllegroDialog();
AllegroSupport loadAllegroDialog(const(char)* libName);
void unloadAllegroDialog();
bool isAllegroDialogLoaded();
AllegroSupport loadedAllegroDialogVersion();

The Static Bindings

Static bindings can be used for static linking and load-time dynamic linking. You may need Allegro development package installed on your system. Allegro releases on GitHub provide precompiled Windows binaries. On OS X, you can use Homebrew. On other systems, they may be available on your system package repository. See Allegro downloads page for details and additional options.

When using load-time dynamic linking, there is a runtime dependency on the shared libraries just as there is when using the run-time dynamic bindings. The difference is that the OS automatically loads the required libraries and bind to their symbols when the program is launched, so there’s no need to call any functions from dynamic binding API such as loadAllegro (they are not even defined in the static bindings). You need to statically link against the import libraries from the development packages (on Windows) or directly against the shared libraries (on other systems).

When using static linking, there are no runtime dependencies, but there is a link-time dependency on static Allegro libraries from the development packages, and all their dependencies in the form of static libraries for the target platform. This is the only option if dynamic linking is not allowed, such as when targeting iOS. See Allegro README for details.

Static bindings are enabled by passing the BindAllegro_Static version. Alternatively, if you use DUB to build your project, you can select the static configuration:

dub.json

"dependencies": {
    "bindbc-allegro5": "~>1.0.0"
},
"subConfigurations": {
    "bindbc-allegro5": "static"
},
"versions": [ "Allegro_Image" ],
"libs": ["liballegro", "liballegro_image"]

This package also recognizes the BindBC_Static version that can be used to enable static binding for all BindBC packages that support this option.

BetterC support

BetterC support is enabled by selecting dynamicBC or staticBC configuration, for dynamic and static bindings respectively. When not using DUB to manage your project, first use DUB to compile the BindBC libraries in the dynamicBC or staticBC configuration, then pass -betterC to the compiler when building your project (and -version=BindAllegro_Static if you selected the staticBC configuration).

Misc

To enable Allegro debugging capabilities, pass ALLEGRO_DEBUG version and link against debug library builds.

To access X11-specific functions, pass ALLEGRO_X11 version.

Authors:
  • Georgy Markov
Dependencies:
none
Versions:
1.2.0 2024-Dec-15
1.1.0 2024-Jan-20
1.0.0 2022-Dec-25
0.0.1 2022-Aug-21
~master 2024-Dec-15
Show all 5 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 34 downloads total

Score:
0.6
Short URL:
bindbc-allegro5.dub.pm