Kumo

A hand-rolled game engine.

git clone https://git.sentomk.me/Kumo.git

demo_scene.h (2058B) · raw


      1 /// @file demo_scene.h
      2 /// @brief A fixed picture that exercises every drawing primitive.
      3 ///
      4 /// A test fixture: tests draw it and compare the hash of the result with a
      5 /// known value, which is how "the same pixels on every platform" is checked.
      6 /// It is a header because the builder compiles only the `*_test` files of the
      7 /// tests directory; the functions are `inline` so that every test program can
      8 /// include it.
      9 #pragma once
     10 
     11 #include "render/frame_buffer.h"
     12 #include "render/raster.h"
     13 
     14 namespace kumo_test {
     15 
     16 /// @brief Width of the picture drawn by draw_demo_scene().
     17 inline constexpr int kDemoWidth = 640;
     18 
     19 /// @brief Height of the picture drawn by draw_demo_scene().
     20 inline constexpr int kDemoHeight = 360;
     21 
     22 /// @brief Draws the demo picture.
     23 ///
     24 /// Changing anything here changes the expected hash in golden_test.cpp
     25 ///
     26 /// @param framebuffer A buffer of kDemoWidth by kDemoHeight pixels.
     27 inline void draw_demo_scene(kumo::FrameBuffer& framebuffer) {
     28   using kumo::Color;
     29   using kumo::make_color;
     30   using kumo::pixel_point;
     31   using kumo::Point;
     32 
     33   kumo::clear(framebuffer, make_color(24, 26, 38));
     34 
     35   kumo::fill_rect(framebuffer, 40, 40, 200, 120, make_color(230, 140, 50));
     36 
     37   // A triangle whose corners are not on pixel boundaries: the values are in
     38   // sixteenths of a pixel.
     39   kumo::fill_triangle(framebuffer, {1004, 700}, {2520, 893}, {1810, 2155},
     40                       make_color(60, 190, 180));
     41 
     42   // A square cut into two triangles that share the diagonal.
     43   const Point tl = pixel_point(380, 60);
     44   const Point tr = pixel_point(560, 60);
     45   const Point br = pixel_point(560, 240);
     46   const Point bl = pixel_point(380, 240);
     47   kumo::fill_triangle(framebuffer, tl, tr, br, make_color(200, 80, 120));
     48   kumo::fill_triangle(framebuffer, tl, br, bl, make_color(120, 90, 210));
     49 
     50   // A fan of lines from one point, reaching past the edge of the buffer.
     51   const Color white = make_color(240, 240, 240);
     52   for (int i = 0; i <= 8; ++i) {
     53     kumo::draw_line(framebuffer, 320, 300, i * 90 - 40, 170, white);
     54   }
     55 }
     56 }  // namespace kumo_test