Show the image in a window

This commit is contained in:
numzero 2024-04-27 18:52:15 +03:00
parent 675d9f837d
commit 354135949f
2 changed files with 12 additions and 8 deletions

View File

@ -8,3 +8,4 @@ edition = "2021"
[dependencies]
rand = "0.8.5"
glm = "0.2.3"
show-image = "0.14.0"

View File

@ -1,12 +1,14 @@
mod mesh_loader;
use std::fs::File;
use std::{env, io};
use std::{env};
use std::error::Error;
use std::f32::consts::PI;
use std::io::{BufRead, BufReader, BufWriter};
use std::io::{BufRead, BufReader};
use std::io::Write;
use rand::Rng;
use glm::*;
use show_image::{ImageInfo, ImageView, WindowOptions};
use crate::mesh_loader::load_mesh;
const W: i32 = 320;
@ -55,7 +57,8 @@ fn ypr_to_mat(ypr: Vec3) -> Mat3 {
m_roll * m_pitch * m_yaw
}
fn main() -> io::Result<()> {
#[show_image::main]
fn main() -> Result<(), Box<dyn Error>> {
let args: Vec<String> = env::args().collect();
let mesh = {
let f = File::open(&args[1])?;
@ -107,11 +110,11 @@ fn main() -> io::Result<()> {
}
}
}
let f = File::create("1.ppm")?;
let mut f = BufWriter::new(f);
write!(f, "P6\n")?;
write!(f, "{W} {H} 255\n")?;
f.write(img.data())?;
let window = show_image::create_window("Raytracing", WindowOptions::default())?;
let image = ImageView::new(ImageInfo::rgb8(W as u32, H as u32), img.data());
window.set_image("image", image)?;
window.wait_until_destroyed()?;
Ok(())
}