Replaced RGB888 with BGR888 since in sdl2-rs they seem to be having a reversed effect
This commit is contained in:
parent
7cba8998c5
commit
b368aad313
|
@ -17,7 +17,7 @@ pub trait Demo {
|
|||
.expect("error in writing file header");
|
||||
|
||||
for i in buf.chunks(4) {
|
||||
match file.write(&format!("{} {} {}\n", i[0], i[1], i[2]).as_bytes()) {
|
||||
match file.write(format!("{} {} {}\n", i[0], i[1], i[2]).as_bytes()) {
|
||||
Ok(_) => (),
|
||||
Err(e) => panic!("couldn't write to {}: {}", self.name(), e.description()),
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ impl crate::Demo for LinearInterpolationY {
|
|||
let origin = Vec3::new(0.0, 0.0, 0.0);
|
||||
|
||||
let mut offset = 0;
|
||||
for j in (0..h) {
|
||||
for j in 0..h {
|
||||
for i in 0..w {
|
||||
// relative offsets
|
||||
// current position to total width/length
|
||||
|
@ -32,7 +32,6 @@ impl crate::Demo for LinearInterpolationY {
|
|||
buf[offset] = ir;
|
||||
buf[offset + 1] = ig;
|
||||
buf[offset + 2] = ib;
|
||||
buf[offset + 3] = 0;
|
||||
offset += 4;
|
||||
}
|
||||
}
|
7
ria-weekend/src/demos/mod.rs
Normal file
7
ria-weekend/src/demos/mod.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
mod linear_interpolation_y;
|
||||
mod simple_sphere;
|
||||
mod ppm_example;
|
||||
|
||||
pub use linear_interpolation_y::LinearInterpolationY;
|
||||
pub use simple_sphere::SimpleSphere;
|
||||
pub use ppm_example::PpmExample;
|
|
@ -8,7 +8,7 @@ impl crate::Demo for PpmExample {
|
|||
|
||||
fn render(&self, buf: &mut Vec<u8>, w: usize, h: usize) {
|
||||
let mut offset = 0;
|
||||
for j in (0..h) {
|
||||
for j in 0..h {
|
||||
for i in 0..w {
|
||||
let color = Vec3::new((i as f32) / (w as f32), (j as f32) / (h as f32), 0.2);
|
||||
|
||||
|
@ -19,7 +19,6 @@ impl crate::Demo for PpmExample {
|
|||
buf[offset] = ir;
|
||||
buf[offset + 1] = ig;
|
||||
buf[offset + 2] = ib;
|
||||
buf[offset + 3] = 255;
|
||||
|
||||
offset += 4;
|
||||
}
|
|
@ -31,7 +31,6 @@ impl crate::Demo for SimpleSphere {
|
|||
buf[offset] = ir;
|
||||
buf[offset + 1] = ig;
|
||||
buf[offset + 2] = ib;
|
||||
buf[offset + 3] = 0;
|
||||
offset += 4;
|
||||
}
|
||||
}
|
|
@ -1,13 +1,10 @@
|
|||
mod demo;
|
||||
mod linear_interpolation_y;
|
||||
mod ppm_example;
|
||||
mod demos;
|
||||
mod ray;
|
||||
mod simple_sphere;
|
||||
mod vec3;
|
||||
|
||||
use demo::Demo;
|
||||
use linear_interpolation_y::LinearInterpolationY;
|
||||
use ppm_example::PpmExample;
|
||||
use demos::{LinearInterpolationY, PpmExample, SimpleSphere};
|
||||
use sdl2::{
|
||||
event::{Event, WindowEvent},
|
||||
keyboard::Keycode,
|
||||
|
@ -17,8 +14,6 @@ use sdl2::{
|
|||
video::Window,
|
||||
EventPump, Sdl,
|
||||
};
|
||||
use simple_sphere::SimpleSphere;
|
||||
use vec3::Vec3;
|
||||
|
||||
fn main() -> Result<(), String> {
|
||||
let sdl_ctx = sdl2::init()?;
|
||||
|
@ -45,11 +40,13 @@ fn main() -> Result<(), String> {
|
|||
|
||||
let texture_creator = canvas.texture_creator();
|
||||
let mut texture = texture_creator
|
||||
.create_texture_static(PixelFormatEnum::RGB888, width as u32, height as u32)
|
||||
.create_texture_static(PixelFormatEnum::BGR888, width as u32, height as u32)
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
let mut active_demo: Box<Demo> = Box::new(LinearInterpolationY);
|
||||
|
||||
//println!("{:?} {:?} {:?}", texture.query(), texture.color_mod(), texture.alpha_mod());
|
||||
|
||||
loop {
|
||||
for event in event_pump.poll_iter() {
|
||||
match event {
|
||||
|
@ -61,27 +58,19 @@ fn main() -> Result<(), String> {
|
|||
Event::KeyUp {
|
||||
keycode: Some(Keycode::Num1),
|
||||
..
|
||||
} => {
|
||||
active_demo = Box::new(PpmExample);
|
||||
}
|
||||
} => active_demo = Box::new(PpmExample),
|
||||
Event::KeyUp {
|
||||
keycode: Some(Keycode::Num2),
|
||||
..
|
||||
} => {
|
||||
active_demo = Box::new(LinearInterpolationY);
|
||||
}
|
||||
} => active_demo = Box::new(LinearInterpolationY),
|
||||
Event::KeyUp {
|
||||
keycode: Some(Keycode::Num3),
|
||||
..
|
||||
} => {
|
||||
active_demo = Box::new(SimpleSphere);
|
||||
}
|
||||
} => active_demo = Box::new(SimpleSphere),
|
||||
Event::KeyUp {
|
||||
keycode: Some(Keycode::S),
|
||||
..
|
||||
} => {
|
||||
active_demo.save_as_ppm(&buffer, width, height);
|
||||
}
|
||||
} => active_demo.save_as_ppm(&buffer, width, height),
|
||||
Event::Window {
|
||||
win_event: WindowEvent::Resized(w, h),
|
||||
..
|
||||
|
@ -90,7 +79,7 @@ fn main() -> Result<(), String> {
|
|||
height = h as usize;
|
||||
buffer.resize(width * height * 4, 0);
|
||||
texture = texture_creator
|
||||
.create_texture_static(PixelFormatEnum::RGB888, width as u32, height as u32)
|
||||
.create_texture_static(PixelFormatEnum::BGR888, width as u32, height as u32)
|
||||
.expect("error in resizing texture");
|
||||
}
|
||||
_ => {}
|
||||
|
|
Loading…
Reference in New Issue
Block a user