/// @file demo_scene.h /// @brief A fixed picture that exercises every drawing primitive. /// /// A test fixture: tests draw it and compare the hash of the result with a /// known value, which is how "the same pixels on every platform" is checked. /// It is a header because the builder compiles only the `*_test` files of the /// tests directory; the functions are `inline` so that every test program can /// include it. #pragma once #include "render/frame_buffer.h" #include "render/raster.h" namespace kumo_test { /// @brief Width of the picture drawn by draw_demo_scene(). inline constexpr int kDemoWidth = 640; /// @brief Height of the picture drawn by draw_demo_scene(). inline constexpr int kDemoHeight = 360; /// @brief Draws the demo picture. /// /// Changing anything here changes the expected hash in golden_test.cpp /// /// @param framebuffer A buffer of kDemoWidth by kDemoHeight pixels. inline void draw_demo_scene(kumo::FrameBuffer& framebuffer) { using kumo::Color; using kumo::make_color; using kumo::pixel_point; using kumo::Point; kumo::clear(framebuffer, make_color(24, 26, 38)); kumo::fill_rect(framebuffer, 40, 40, 200, 120, 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(framebuffer, {1004, 700}, {2520, 893}, {1810, 2155}, make_color(60, 190, 180)); // A square cut into two triangles that share the diagonal. const Point tl = pixel_point(380, 60); const Point tr = pixel_point(560, 60); const Point br = pixel_point(560, 240); const Point bl = pixel_point(380, 240); kumo::fill_triangle(framebuffer, tl, tr, br, make_color(200, 80, 120)); kumo::fill_triangle(framebuffer, tl, br, bl, make_color(120, 90, 210)); // A fan of lines from one point, reaching past the edge of the buffer. const Color white = make_color(240, 240, 240); for (int i = 0; i <= 8; ++i) { kumo::draw_line(framebuffer, 320, 300, i * 90 - 40, 170, white); } } } // namespace kumo_test