45 releases

Uses old Rust 2015

0.0.46 May 26, 2024
0.0.45 Nov 24, 2023
0.0.44 Aug 23, 2022
0.0.43 Jul 21, 2022
0.0.1 Dec 31, 2014

#55 in Rendering

Download history 16/week @ 2024-07-22 6/week @ 2024-07-29 15/week @ 2024-08-12 2/week @ 2024-08-19 23/week @ 2024-08-26 21/week @ 2024-09-02 25/week @ 2024-09-09 24/week @ 2024-09-16 77/week @ 2024-09-23 31/week @ 2024-09-30 20/week @ 2024-10-14 4/week @ 2024-10-21 13/week @ 2024-10-28 46/week @ 2024-11-04

83 downloads per month
Used in allegro_examples

Zlib license

175KB
6K SLoC

RustAllegro

Build Status

A thin Rust wrapper of Allegro 5.

Game loop example

extern crate allegro;
extern crate allegro_font;

use allegro::*;
use allegro_font::*;

allegro_main!
{
    let core = Core::init().unwrap();
    let font_addon = FontAddon::init(&core).unwrap();

    let display = Display::new(&core, 800, 600).unwrap();
    let timer = Timer::new(&core, 1.0 / 60.0).unwrap();
    let font = Font::new_builtin(&font_addon).unwrap();

    let queue = EventQueue::new(&core).unwrap();
    queue.register_event_source(display.get_event_source());
    queue.register_event_source(timer.get_event_source());

    let mut redraw = true;
    timer.start();
    'exit: loop
    {
        if redraw && queue.is_empty()
        {
            core.clear_to_color(Color::from_rgb_f(0.0, 0.0, 0.0));
            core.draw_text(&font, Color::from_rgb_f(1.0, 1.0, 1.0),
                (display.get_width() / 2) as f32, (display.get_height() / 2) as f32,
                FontAlign::Centre, "Welcome to RustAllegro!");
            core.flip_display();
            redraw = false;
        }

        match queue.wait_for_event()
        {
            DisplayClose{..} => break 'exit,
            TimerTick{..} => redraw = true,
            _ => (),
        }
    }
}

Documentation

See docs.rs. Note that it is very incomplete. You'll likely want to refer back to Allegro's documentation somewhat heavily at this time.

Packages

The included packages are:

Wrappers:

Bindings:

Examples:

General usage notes

The allegro-sys package (and, transitively, the rest of the packages) detects which version of Allegro to bind by parsing the C header. The build script will look for it in some common locations, but sometimes you will need to help it by specifying the ALLEGRO_INCLUDE_DIR environment variable when invoking cargo build. This directory should contain the allegro5 directory with all of the headers inside it. The build script will define the following two metadata entries that the crates that depend on it can use to determine which version is used:

  • sub_version - The sub version of Allegro (e.g. for 5.1.10 the sub version is 1)

  • wip_version - The wip version of Allegro (e.g. for 5.1.10 the wip version is 10).

Note that the Core::init() will attempt to verify that the binding corresponds to the version of the library you're linking to.

There are a few features that might come in useful:

  • link_none - Do not try to link the standard Allegro libraries, in case you want to link the monolith library or have other needs.
  • link_debug - Link to the debug versions of the Allegro libraries. Can be combined with link_static.
  • link_static - Link to the static versions of the Allegro libraries. Note that you'll have to link the various dependency libraries yourself. Can be combined with link_debug.

Additionally, you can specify a link directory by setting a ALLEGRO_LINK_DIR.

Windows notes

RustAllegro works well with the official pre-compiled binaries. First, download the official binaries from http://liballeg.org. You'll want to match the ABI of your Rust installation. GNU ABI on 32 bit can load Allegro 32 bit MSVC binaries, but otherwise you'll want to match the platform and ABI exactly. Let's say you extract the binaries to C:/allegro. That directory will contain the include, bin and lib directories. To compile and run the RustAllegro examples, do the following from the RustAllegro's examples directory:

  • If you're using MSYS:
export ALLEGRO_INCLUDE_DIR=C:/allegro/include
export ALLEGRO_LINK_DIR=C:/allegro/lib
cargo build
  • If you're using cmd directly:
set ALLEGRO_INCLUDE_DIR=C:/allegro/include
set ALLEGRO_LINK_DIR=C:/allegro/lib
cargo build

Now you need to copy the Allegro DLLs next to the generated executables (which will probably be under target/debug directory). Now you should be able to run the examples (make sure to run them from RustAllegro's examples directory, so they can find the various data files they require).

Dependencies

~61KB