commit 3a62df4f48237633e49548c905979e988857989d Author: Erin Date: Wed Aug 2 14:34:19 2017 -0500 shaders diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..324c57f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +target/ +**/*.rs.bk diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..915d653 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,129 @@ +[root] +name = "minifb_shit" +version = "0.1.0" +dependencies = [ + "minifb 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "dylib" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "gcc" +version = "0.3.51" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "gdi32-sys" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "kernel32-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libc" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "libc" +version = "0.2.24" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "minifb" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)", + "gdi32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "kernel32-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "user32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "x11-dl 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "redox_syscall" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "time" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "user32-sys" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "x11-dl" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "dylib 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[metadata] +"checksum dylib 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cdff070fc467d71f23c5ac5ebfa0867e8f31146ef529b777723e8cba815e47ae" +"checksum gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)" = "120d07f202dcc3f72859422563522b66fe6463a4c513df062874daad05f85f0a" +"checksum gdi32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "65256ec4dc2592e6f05bfc1ca3b956a4e0698aa90b1dff1f5687d55a5a3fd59a" +"checksum kernel32-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e014dab1082fd9d80ea1fa6fcb261b47ed3eb511612a14198bb507701add083e" +"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +"checksum libc 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "e32a70cf75e5846d53a673923498228bbec6a8624708a9ea5645f075d6276122" +"checksum libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)" = "38f5c2b18a287cf78b4097db62e20f43cace381dc76ae5c0a3073067f78b7ddc" +"checksum minifb 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e6b5aaa56c930092d9e4673ed7e04935893c8d1a53372ed11e6025606c90e792" +"checksum redox_syscall 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)" = "e4a357d14a12e90a37d658725df0e6468504750b5948b9710f83f94a0c5818e8" +"checksum time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "ffd7ccbf969a892bf83f1e441126968a07a3941c24ff522a26af9f9f4585d1a3" +"checksum user32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6717129de5ac253f5642fc78a51d0c7de6f9f53d617fc94e9bae7f6e71cf5504" +"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" +"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" +"checksum x11-dl 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "349db8b7b8be6031ac00cb49ac8b8389e5e1b1743300d2873223be80d35fd216" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..2d3b20f --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "minifb_shit" +version = "0.1.0" +authors = ["Erin "] + +[dependencies] +minifb = "0.9" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..801e525 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,68 @@ +extern crate minifb; + +use std::error::Error; +use minifb::{Window, WindowOptions, Key}; + +const WIDTH: usize = 640; +const HEIGHT: usize = 480; + +trait Shader { + fn shade(&mut self, x: usize, y: usize) -> u32; +} + +struct TestShader { + noise: u32, + carry: u32, + pub seed: u32, +} +impl TestShader { + pub fn new(seed: u32) -> TestShader { + TestShader { + noise: 0, + carry: 0, + seed + } + } +} +impl Shader for TestShader { + fn shade(&mut self, x_: usize, y_: usize) -> u32 { + self.noise = self.seed; + self.noise >>= 3; + self.noise ^= self.seed; + self.carry = self.noise & 1; + self.noise >>= 1; + self.seed >>=1; + self.seed |= (self.carry << 30); + self.noise &= 0xff; + + return (self.noise << 16) | (self.noise << 8) | self.noise; + } +} + +fn run() -> Result<(), Box> { + let mut buffer: Vec = vec![0; WIDTH * HEIGHT]; + let mut window = Window::new("minifb", + WIDTH, + HEIGHT, + WindowOptions::default())?; + + let mut shader = TestShader::new(0xcafe); + + while window.is_open() && !window.is_key_down(Key::Escape) { + for x in 0..WIDTH { + for y in 0..HEIGHT { + buffer[y*WIDTH + x] = shader.shade(x, y); + } + } + + window.update_with_buffer(&buffer); + } + + Ok(()) +} + +fn main() { + if let Err(e) = run() { + println!("Error: {}", e); + } +} \ No newline at end of file