diff --git a/sysdata/libraries/render/src/lib.hb b/sysdata/libraries/render/src/lib.hb index 492f89f..66a68ee 100644 --- a/sysdata/libraries/render/src/lib.hb +++ b/sysdata/libraries/render/src/lib.hb @@ -42,6 +42,7 @@ clear := mode.clear put_surface := mode.put_surface put_scaled := mode.put_scaled put_tri_wireframe := mode.put_tri_wireframe +put_tri_filled := mode.put_tri_filled // thanks peony for these three! put_trirect := mode.put_trirect put_vline := mode.put_vline diff --git a/sysdata/libraries/render/src/software.hb b/sysdata/libraries/render/src/software.hb index fd50087..2b302f9 100644 --- a/sysdata/libraries/render/src/software.hb +++ b/sysdata/libraries/render/src/software.hb @@ -1,4 +1,4 @@ -.{math, memory, dt} := @use("../../stn/src/lib.hb"); +.{math, memory, dt, log} := @use("../../stn/src/lib.hb"); .{Color} := @use("lib.hb"); .{Vec2} := math @@ -68,8 +68,8 @@ indexptr := fn(surface: Surface, x: int, y: int): ^Color { return surface.buf + @inline(index, surface, x, y) } -put_pixel := fn(surface: Surface, pos: Vec2(int), color: Color): void { - *@inline(indexptr, surface, pos.x, pos.y) = color +put_pixel := fn(surface: Surface, pos: Vec2(uint), color: Color): void { + *@inline(indexptr, surface, @intcast(pos.x), @intcast(pos.y)) = color return } @@ -329,9 +329,36 @@ put_hline := fn(surface: Surface, y: int, x0: int, x1: int, color: Color): void return } -put_tri_wireframe := fn(surface: Surface, p0: Vec2(uint), p1: Vec2(uint), p2: Vec2(uint), color: Color): void { +put_tri_wireframe := fn(surface: Surface, p0: Vec2(int), p1: Vec2(int), p2: Vec2(int), color: Color): void { put_line(surface, p0, p1, color) put_line(surface, p1, p2, color) put_line(surface, p2, p0, color) + return +} + +put_tri_filled := fn(surface: Surface, p0: Vec2(uint), p1: Vec2(uint), p2: Vec2(uint), color: Color): void { + if p2.y < p0.y { + tmp := p0 + p0 = p2 + p2 = tmp + } + + if p1.y < p0.y { + tmp := p0 + p0 = p1 + p1 = tmp + } + + if p2.y < p1.y { + tmp := p1 + p1 = p2 + p2 = tmp + } + + y := p0.y + loop if y > p2.y break else { + y += 1 + } + return } \ No newline at end of file diff --git a/sysdata/programs/render_example/src/examples/cube.hb b/sysdata/programs/render_example/src/examples/cube.hb index 042e4da..0318b98 100644 --- a/sysdata/programs/render_example/src/examples/cube.hb +++ b/sysdata/programs/render_example/src/examples/cube.hb @@ -4,7 +4,8 @@ render := @use("../../../../libraries/render/src/lib.hb") example := fn(): void { screen := render.init(true) loop { - render.put_tri_wireframe(screen, .(10, 10), .(128, 256), .(512, 512), .(255, 255, 255, 255)) + render.clear(screen, render.black) + render.put_tri_filled(screen, .(128, 256), .(512, 512), .(10, 10), .(255, 255, 255, 255)) render.sync(screen) } return