#[macro_use] extern crate shadiertoy; use shadiertoy::{Window, Game, Shader}; use std::time::Instant; const SHADER_PRELUDE: &'static str = " #version 130 uniform vec2 iResolution; uniform float iTime; out vec4 color; void mainImage(out vec4, in vec2); void main() { mainImage(color, gl_FragCoord.xy); } "; pipeline!(globals { iTime: Global, iResolution: Global<[f32; 2]>, color: RenderTarget, }); struct Basic { shader: Shader, start: Instant, } impl Game for Basic { fn new(window: &mut Window) -> Self { let shader = SHADER_PRELUDE.to_owned() + include_str!("nebula.frag"); let shader = window.shader(globals::new(), shader.as_bytes()).unwrap(); Basic { shader, start: Instant::now(), } } fn draw(&mut self, window: &mut Window) { let time = self.start.elapsed(); let time = time.as_secs() as f32 + time.subsec_nanos() as f32 * 1e-9; let resolution = window.size() .map(|(w, h)| [w as f32, h as f32]) .unwrap_or([0.0; 2]); window.draw(&self.shader, |color, _| globals::Data { iTime: &time, iResolution: &resolution, color, }); } } pub fn main() { Basic::run() }