#x11 #api #graphics #bindings #linux #mlx #beginner

minilibx

Rust ffi bindings to the 42 minilibx api for X11 on linux

4 releases

0.2.1 May 2, 2020
0.2.0 May 1, 2020
0.1.1 May 1, 2020
0.1.0 May 1, 2020

#560 in Graphics APIs

MIT license

28KB
607 lines

Minilibx for the rust novice

About

These are the rust ffi bindings for the minilibX C api.
The api is meant for beginners to learn the basics of graphics development.
The minilibx itself is a wrapper around X11 utilites to provide a simple library for graphics development.

Dependencies

How To Install

First, you need to have these libraries installed:

  • libX11
  • libXext
  • libmlx.a (either in /usr/lib* or /usr/local/lib)

to install libmlx, you can do

$ git clone git@github.com:42Paris/minilibx-linux /tmp/minilibx-linux
$ cd /tmp/minilibx-linux
$ make
$ sudo cp libmlx.a /usr/local/lib

In your project:

[dependencies]
minilibx = "0.2.1"

Example

extern crate minilibx;

use minilibx::{Mlx, MlxError};
use std::process;

fn main() {
    let mlx = Mlx::new().unwrap();

    let width = 1080;
    let height = 720;
    let window = mlx.new_window(width, height, "Mlx example").unwrap();

    let image = match mlx.new_image(width, height) {
        Ok(img) => img,
        Err(e) => match e {
            MlxError::Any(s) => return println!("{}", s),
            _ => return,
        },
    };

    println!("{}", image.size_line);

    window.key_hook(
        move |keycode, _| {
            // you can also check keycodes using the `xev` command on linux
            println!("{}", keycode);

            if keycode == 113 {
                process::exit(0);
            } else if keycode == 97 {
                let x = width / 2;
                let y = height / 2;
                let color = 0xffffff;
                mlx.pixel_put(&window, x, y, color);
            }
        },
        &(),
    );

    // this will loop forever
    mlx.event_loop();
}

No runtime deps