A Rust wrapper and bindings of Allegro 5 game programming library

Overview

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 here. 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).

Comments
  • Some updates to get the example to build and run on Windows.

    Some updates to get the example to build and run on Windows.

    Trying to build the allegro-sys crate was failing because two files only contain a path to another Rust file. Wrapping those paths with the include! macro fixes it.

    opened by dradtke 5
  • Unstable features prevent building on Rust beta

    Unstable features prevent building on Rust beta

    RustAllegro cannot be build on Rust beta since it uses a unstable features libc, std_misc, and optin_builtin_traits.

    • libc should be replaced with libc crate.
    • optin_builtin_traits should be replaced with marker types.
    • I am not sure how to replace std_misc.
    opened by Ape 4
  • How to pass custom directory with libraries?

    How to pass custom directory with libraries?

    I have allegro installed in ~/libs/root/ directory - not as a system library. I've few other libraries there. I already passed ALLEGRO_INCLUDE_DIR=/home/capsel/libs/root/include. I can't find a way to pass /home/capsel/libs/root/lib as a directory with libraries - similar to CFLAGS="-L/home/capsel/libs/root/lib".

    Is there a way to do it?

    opened by CapSel 3
  •  al_hide_mouse_cursor is missing from allegro-sys

    al_hide_mouse_cursor is missing from allegro-sys

    So i was looking on a way to hide the cursor in the allegro docs, found al_hide_mouse_cursor, tried looking for something similar in the rust wrapper, couldn't find it, so i looked at the allegro-sys crate, and couldn't even find it there, tried adding it manually in the mouse.rs file then using that local version of the sys crate but because it doesn't allow me to use the returned pointer from the allegro wrapper because it's a "different version of the crate" it required me to change allegro and the other addons to local versions as well, it's really messy that i had to do all of that just for a missing method

    opened by ZackGabri 1
  • autoderive Eq and Hash for KeyCode

    autoderive Eq and Hash for KeyCode

    Related to https://github.com/SiegeLord/RustAllegro/issues/8

    E.g.

    let pressed_keys = HashSet::new();
    
    match queue.wait_for_event() {
      KeyDown { keycode: k, .. } => {
        pressed_keys.insert(k);
      }
      KeyUp { keycode: k, .. } => {
        pressed_keys.remove(&k);
      },
      _ => (),
    }
    
    opened by ibodrov 1
  • Fix link_static for allegro_image

    Fix link_static for allegro_image

    From looking through previous commits, it seems like 'manual_link' is legacy. It stops the link_static feature flag from taking effect.

    Edit: Ah, this breaks the normal build without the feature flags.

    opened by t-mw 1
  • fail -> panic

    fail -> panic

    Sorry I broke your code with rust-lang/rust#17894 ! Here's a fix :heart:

    (this is a semi-automatic PR, so sorry if it's not perfect. Let me know and I'll fix any problems.)

    opened by steveklabnik 0
  • How do I force static monolith linking?

    How do I force static monolith linking?

    Hi, Since I'm a Windows user, I don't want to mess with dll's. Instead I created the allegro as a monolith. Now how can I tell Rust to use this library?

    opened by SeanTolstoyevski 1
  • Possible reorganisation of the package (making more use of features)

    Possible reorganisation of the package (making more use of features)

    I'm still relatively new to Rust (let alone RustAllegro!) - however, the thought just occurred to me that - as some of the addons are so tiny - it might be worth not having them in separate crates, but instead conditionally including modules using crate features (with some sensible defaults). Forgive me if this is a daft idea - I'd be interested to know why it wouldn't work, if so.

    As an example, we'd include Allegro and the font addon into the readme's hello world like this:

    use allegro::*;
    use allegro::font::*;
    

    ...and would either have font included in the default set of features, or ask that the user enabled it:

    allegro = { version = "0.1.0", features = ["font"] }
    
    opened by snoopdouglas 1
Owner
null
Solana Game Server is a decentralized game server running on Solana, designed for game developers

Solana Game Server* is the first decentralized Game Server (aka web3 game server) designed for game devs. (Think web3 SDK for game developers as a ser

Tardigrade Life Sciences, Inc 16 Dec 1, 2022
A wrapper around SDL2's game controller API.

fishsticks System for handling gamepad input, using SDL2's game controller API as the backend. License Fishsticks is dual-licensed under either Apache

null 7 Dec 8, 2022
Victorem - easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust.

Victorem Easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust. Example Cargo.toml [dependencies] vict

Victor Winbringer 27 Jan 7, 2023
2-player game made with Rust and "ggez" engine, based on "Conway's Game of Life"

fight-for-your-life A 2-player game based on the "Conway's Game of Life", made with Rust and the game engine "ggez". Create shapes on the grid that wi

Petros 3 Oct 25, 2021
A tetris game I wrote in rust using ncurses. I'm sure that there's a better way to write a tetris game, and the code may be sus, but it techinically works

rustetris A tetris game I wrote in rust using ncurses. I'm sure that there's a better way to write a tetris game, and the code may be sus, but it tech

Eric G 3 Oct 15, 2022
Wasm game of life - A Rust and WebAssembly tutorial implementing the Game of Life

wasm_game_of_life Conway's Game of Life in Rust and WebAssembly Contributing | Chat Built with ?? ?? by The Rust and WebAssembly Working Group About T

Rust and WebAssembly 236 Dec 24, 2022
Managed game servers, matchmaking, and DDoS mitigation that lets you focus on building your game

Managed game servers, matchmaking, and DDoS mitigation that lets you focus on building your game. Home - Docs - Twitter - Discord ?? Features Everythi

Rivet 58 Jun 25, 2023
A game of snake written in Rust using the Bevy game engine, targeting WebGL2

Snake using the Bevy Game Engine Prerequisites cargo install cargo-make Build and serve WASM version Set your local ip address in Makefile.toml (loca

Michael Dorst 0 Dec 26, 2021
Conway's Game of Life implemented for Game Boy Advance in Rust

game-of-life An implementation of a Conway's Game of Life environment on GBA. The ultimate game should have two modes: Edit and Run mode which can be

Shane Snover 1 Feb 16, 2022
2d Endless Runner Game made with Bevy Game Engine

Cute-runner A 2d Endless Runner Game made with Bevy Game Engine. Table of contents Project Infos Usage Screenshots Disclaimer Project Infos Date: Sept

JoaoMarinho 2 Jul 15, 2022
A game for the game jam "1-Button Jam 2021"

One click ninja A game for the game jam "1-Button Jam 2021" written in Rust with the Bevy engine. A rhythm game, where you play a soldier that can def

Alex Helfet 7 Apr 12, 2022
A game made in one week for the Bevy engine's first game jam

¿Quien es el MechaBurro? An entry for the first Bevy game jam following the theme of "Unfair Advantage." It was made in one week using the wonderful B

mike 20 Dec 23, 2022
A Client/Server game networking plugin using QUIC, for the Bevy game engine.

Bevy Quinnet A Client/Server game networking plugin using QUIC, for the Bevy game engine. Bevy Quinnet QUIC as a game networking protocol Features Roa

Gilles Henaux 65 Feb 20, 2023
🎳 Rust binding and wrapper over NVIDIA PhysX 🦀

?? physx-rs Rust binding and wrapper over NVIDIA PhysX, a popular and mature physics engine particularly well-suited for games. Created and maintained

Embark 489 Dec 29, 2022
Rust bindings for libtcod 1.6.3 (the Doryen library/roguelike toolkit)

Warning: Not Maintained This project is no longer actively developed or maintained. Please accept our apologies. Open pull requests may still get merg

Tomas Sedovic 226 Nov 17, 2022
A simple and minimal game engine library built in rust.

Neptune A brand new free, open-source minimal and compact game engine built in rust. Design Goals We plan to make Neptune a small and minimal engine,

Levitate 17 Jan 25, 2023
Scion is a tiny 2D game library built on top of wgpu, winit and legion.

Scion is a 2D game library made in rust. Please note that this project is in its first milestones and is subject to change according to convience need

Jérémy Thulliez 143 Dec 25, 2022
Plotting library for the Bevy game engine with a focus on esthetics and interactivity

Plotting library for the Bevy game engine with a focus on esthetics and interactivity. It can handle both data points (see the "minimal", "markers", a

Eli 40 Dec 25, 2022
Rust library to create a Good Game Easily

ggez What is this? ggez is a Rust library to create a Good Game Easily. The current version is 0.6.0-rc0. This is a RELEASE CANDIDATE version, which m

null 3.6k Jan 7, 2023