Files
pbio/README.md
T

58 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# pbio: simple pixel buffer I/O
Pixelbuffer-basiertes Fenster mit Palette-Lookup-Renderer (GLFW + wgpu).
pbio nimmt einen Bytearray, interpretiert diesen als 8-Bit-Pixelbuffer und rendert ihn auf ein Fenster. Optional mit Letterbox für ein festes Seitenverhältnis
## Verwendung
```rust
use pbio::{Event, Key, Platform, PlatformConfig};
fn main() {
let mut p = Platform::new(PlatformConfig {
title: "Demo".into(),
window_size: (1024, 768),
framebuffer_size: (320, 240),
..Default::default()
});
while !p.should_close() {
p.poll_events(None);
for ev in p.drain_events() {
if let Event::Key { key: Key::Escape, pressed: true, .. } = ev {
p.request_close();
}
}
let (w, _h) = p.framebuffer_size();
let fb = p.framebuffer_mut();
for (i, px) in fb.iter_mut().enumerate() {
*px = ((i as u32 % w) ^ (i as u32 / w)) as u8;
}
p.present();
}
}
```
## API-Überblick
- `PlatformConfig` Titel, Fenster-/Framebuffer-Größe, optionales
`aspect_ratio` (Letterbox), Palette, VSync. Default = 800×600 Fenster,
320×240 Framebuffer, 4:3, `palette::RGB332`.
- `Platform::new(cfg)` Fenster + GPU-Pipeline aufsetzen.
- `poll_events(timeout)` GLFW-Events einlesen (`None` = blockierend).
- `drain_events()` Iterator über `Event` (`Key`, `Char`, `MouseMove`,
`MouseBtn`, `Resize`, `CloseRequested`).
- `framebuffer_mut()` `&mut [u8]` der Länge `w*h`, je Pixel ein Paletten-Index.
- `present()` Frame auf das Fenster bringen.
- `should_close()` / `request_close()`.
## Paletten
`palette::RGB332` ist als Default eingebaut. Eigene Paletten sind ein
`[[u8; 3]; 256]` (RGB pro Index) und werden über `PlatformConfig::palette`
übergeben.