Crates.io | minilibx |
lib.rs | minilibx |
version | 0.2.1 |
source | src |
created_at | 2020-05-01 19:03:47.318576 |
updated_at | 2020-05-02 10:50:04.749648 |
description | Rust ffi bindings to the 42 minilibx api for X11 on linux |
homepage | |
repository | https://github.com/kyazdani42/minilibx-rs |
max_upload_size | |
id | 236343 |
size | 29,913 |
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.
First, you need to have these libraries installed:
/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"
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();
}