Kumo
A hand-rolled game engine.
git clone https://git.sentomk.me/Kumo.git
commit 0db8f6b8ebae917eb20f2e46857b64e0f3d82bea parent 1e8549429bbe973428096003a08b801d626494b3 Author: sentomk <sentomk@proton.me> Date: Thu, 8 Oct 2026 21:39:22 +0800 feat: render a test frame headlessly and print its hash Draw a rectangle, a triangle with subpixel corners, a quad made of two triangles and a fan of clipped lines into a FrameBuffer, write it to build/frame.tga and print its hash, which must be the same on every platform: 635d63193c43fe8a. Before drawing, check that splitting a rectangle into two triangles draws every pixel exactly once, in both windings. Diffstat:
| A | src/main.cpp | | | 83 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 83 insertions(+), 0 deletions(-)
diff --git a/src/main.cpp b/src/main.cpp @@ -0,0 +1,83 @@ +#include <cinttypes> +#include <cstdio> + +#include "render/frame_buffer.h" +#include "render/raster.h" + +namespace { + +using kumo::Color; +using kumo::FrameBuffer; +using kumo::Point; + +/// @brief Splits the rectangle with corners (x0, y0) and (x1, y1) into two +/// triangles and checks that each of its pixels is drawn exactly once. +/// +/// The diagonal runs through pixel centers, which is the case the top-left +/// rule exists for. The second triangle is given in the opposite winding, to +/// check that the orientation is normalized. +bool check_split_rect(int x0, int y0, int x1, int y1) { + const Color kOn = 0xFFFFFFFF; + FrameBuffer first(64, 64); + FrameBuffer second(64, 64); + const Point tl = kumo::pixel_point(x0, y0); + const Point tr = kumo::pixel_point(x1, y0); + const Point br = kumo::pixel_point(x1, y1); + const Point bl = kumo::pixel_point(x0, y1); + kumo::fill_triangle(first, tl, tr, br, kOn); + kumo::fill_triangle(second, tl, bl, br, kOn); + + for (int y = 0; y < 64; ++y) { + for (int x = 0; x < 64; ++x) { + const int drawn = (first.at(x, y) != 0) + (second.at(x, y) != 0); + const bool inside = x >= x0 && x < x1 && y >= y0 && y < y1; + if (drawn != (inside ? 1 : 0)) return false; + } + } + return true; +} + +} // namespace + +int main() { + if (!check_split_rect(8, 8, 48, 48) || !check_split_rect(5, 11, 42, 34) || + !check_split_rect(0, 0, 64, 64)) { + std::printf("shared edge check: FAILED\n"); + return 1; + } + std::printf("shared edge check: ok\n"); + + FrameBuffer frame(640, 360); + kumo::clear(frame, kumo::make_color(24, 26, 38)); + + kumo::fill_rect(frame, 40, 40, 200, 120, kumo::make_color(230, 140, 50)); + + // A triangle whose corners are not on pixel boundaries: the values are in + // sixteenths of a pixel. + kumo::fill_triangle(frame, {1004, 700}, {2520, 893}, {1810, 2155}, + kumo::make_color(60, 190, 180)); + + // A square cut into two triangles that share the diagonal. + const Point tl = kumo::pixel_point(380, 60); + const Point tr = kumo::pixel_point(560, 60); + const Point br = kumo::pixel_point(560, 240); + const Point bl = kumo::pixel_point(380, 240); + kumo::fill_triangle(frame, tl, tr, br, kumo::make_color(200, 80, 120)); + kumo::fill_triangle(frame, tl, br, bl, kumo::make_color(120, 90, 210)); + + // A fan of lines from one point, reaching past the edge of the buffer. + const Color white = kumo::make_color(240, 240, 240); + for (int i = 0; i <= 8; ++i) { + kumo::draw_line(frame, 320, 300, i * 90 - 40, 170, white); + } + + const uint64_t hash = kumo::hash_pixels(frame); + std::printf("frame hash: %016" PRIx64 "\n", hash); + + if (!kumo::write_tga(frame, "build/frame.tga")) { + std::printf("could not write build/frame.tga\n"); + return 1; + } + std::printf("wrote build/frame.tga\n"); + return 0; +}
