extern crate minilibx; use minilibx::{Endian, 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, }, }; let _bytes_per_pixel = image.bits_per_pixel / 8; let offset = image.size_line / 2 + image.size_line * height / 2; for i in 1..100 { // we assume there are 32 bits per pixel here, because its just an example. // color encoding can go from 8 bits to 48 bits. let offset = offset + i * 4; match image.endian { Endian::Little => { image.write_to(offset + 2, 0xff); // R image.write_to(offset + 1, 0x0); // G image.write_to(offset, 0x0); // B } Endian::Big => { image.write_to(offset, 0xff); // R image.write_to(offset + 1, 0x0); // G image.write_to(offset + 2, 0x0); // B } } } window.key_hook( move |keycode, _| { // you can also check keycodes using the `xev` command println!("{}", keycode); // `q` if keycode == 113 { process::exit(0); // Enter } else if keycode == 97 { let x = width / 2; let y = height / 2; let color = 0xffffff; for i in 0..50 { mlx.pixel_put(&window, x + i, y + i, color); } } else if keycode == 98 { mlx.put_image_to_window(&window, &image, 0, 0); } }, &(), ); // this will loop forever mlx.event_loop(); }