use sevenx_engine::*;
use sevenx_engine::world::World;
struct PostProcessDemo {
post_processor: PostProcessor,
current_effect: usize,
time: f32,
toggle_cooldown: f32,
}
impl GameState for PostProcessDemo {
fn new() -> Self {
let mut post_processor = PostProcessor::new();
post_processor.add_effect(PostEffect::Bloom {
threshold: 0.7,
intensity: 0.5,
});
Self {
post_processor,
current_effect: 0,
time: 0.0,
toggle_cooldown: 0.0,
}
}
fn update(&mut self, dt: f32, input: &sevenx_engine::input::InputHandler, _world: &mut World) {
self.time += dt;
self.toggle_cooldown -= dt;
if input.is_key_pressed(KeyCode::Space) && self.toggle_cooldown <= 0.0 {
self.toggle_cooldown = 0.3;
self.current_effect = (self.current_effect + 1) % 4;
self.post_processor.clear_effects();
match self.current_effect {
0 => {
self.post_processor.add_effect(PostEffect::Bloom {
threshold: 0.7,
intensity: 0.5,
});
}
1 => {
self.post_processor.add_effect(PostEffect::Vignette {
intensity: 0.8,
radius: 0.8,
});
}
2 => {
self.post_processor.add_effect(PostEffect::ColorGrading {
contrast: 1.5,
saturation: 1.3,
brightness: 0.1,
});
}
3 => {
self.post_processor.add_effect(PostEffect::Bloom {
threshold: 0.6,
intensity: 0.7,
});
self.post_processor.add_effect(PostEffect::Vignette {
intensity: 0.5,
radius: 0.9,
});
}
_ => {}
}
}
}
fn draw(&mut self, _world: &World, frame: &mut [u8]) {
let width = 800;
let height = 600;
for y in 0..height {
for x in 0..width {
let idx = ((y * width + x) * 4) as usize;
let fx = x as f32 / width as f32;
let fy = y as f32 / height as f32;
let r = ((fx * 255.0) as u8).wrapping_add((self.time * 50.0) as u8);
let g = ((fy * 255.0) as u8).wrapping_add((self.time * 30.0) as u8);
let b = (((fx + fy) * 128.0) as u8).wrapping_add((self.time * 70.0) as u8);
let cx = 400.0 + (self.time * 2.0).cos() * 200.0;
let cy = 300.0 + (self.time * 2.0).sin() * 150.0;
let dist = ((x as f32 - cx).powi(2) + (y as f32 - cy).powi(2)).sqrt();
if dist < 50.0 {
frame[idx] = 255;
frame[idx + 1] = 255;
frame[idx + 2] = 100;
} else {
frame[idx] = r;
frame[idx + 1] = g;
frame[idx + 2] = b;
}
frame[idx + 3] = 255;
}
}
self.post_processor.apply(frame, width, height);
}
}
fn main() {
let config = EngineConfig::default()
.with_title("SevenX Engine - Post-Processing Demo (Press SPACE)")
.with_size(800, 600);
let engine = Engine::with_config(config);
engine.run::<PostProcessDemo>();
}