4个版本
0.2.1 | 2020年5月2日 |
---|---|
0.2.0 | 2020年5月1日 |
0.1.1 | 2020年5月1日 |
0.1.0 | 2020年5月1日 |
#560 in 图形API
28KB
607 行
minilibx面向Rust初学者
关于
这是对minilibX C API的Rust ffi绑定。
该API旨在让初学者学习图形开发的基础。
minilibx本身是一个X11工具的包装器,提供用于图形开发的简单库。
依赖项
- Linux。
- 一个编译器
- mlx库
如何安装
首先,您需要安装以下库
- libX11
- libXext
- libmlx.a(位于
/usr/lib*
或/usr/local/lib
中)
要安装libmlx,您可以执行以下操作
$ git clone [email protected]:42Paris/minilibx-linux /tmp/minilibx-linux
$ cd /tmp/minilibx-linux
$ make
$ sudo cp libmlx.a /usr/local/lib
在您的项目中
[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();
}