use euc::{buffer::Buffer2d, rasterizer, DepthStrategy, Pipeline};
struct Triangle;
impl Pipeline for Triangle {
type Vertex = [f32; 4];
type VsOut = ();
type Pixel = u32;
#[inline(always)]
fn vert(&self, pos: &[f32; 4]) -> ([f32; 4], Self::VsOut) {
(*pos, ())
}
#[inline(always)]
fn get_depth_strategy(&self) -> DepthStrategy {
DepthStrategy::None
}
#[inline(always)]
fn frag(&self, _: &Self::VsOut) -> Self::Pixel {
let bytes = [255, 0, 0, 255];
(bytes[2] as u32) << 0
| (bytes[1] as u32) << 8
| (bytes[0] as u32) << 16
| (bytes[3] as u32) << 24
}
}
const W: usize = 640;
const H: usize = 480;
fn main() {
let mut color = Buffer2d::new([W, H], 0);
Triangle.draw::<rasterizer::Triangles<(f32,)>, _>(
&[
[-1.0, -1.0, 0.0, 1.0],
[1.0, -1.0, 0.0, 1.0],
[0.0, 1.0, 0.0, 1.0],
],
&mut color,
None,
);
let mut win = minifb::Window::new("Triangle", W, H, minifb::WindowOptions::default()).unwrap();
while win.is_open() {
win.update_with_buffer(color.as_ref(), W, H).unwrap();
}
}