Theme Catppuccin
Make yourself at homeCatppuccin

A softer light for long learning sessions.

Appearance

Loading your preference…

Dark palette

Choose a dark palette to try it.

Light uses Latte. Your choices stay in this browser.

Back to your source shelf

Inside the companion

First Light

Make your first CPU image, rasterize triangles, and trace an allocation budget.

Project files 15

Describe a triangle study

Screen-space vertices, raster scenes, and the rasterizer interface.

25 lines raster_lab.hpp
#pragma once
#include "prism/renderer.hpp"
#include <array>

namespace prism {

// Already projected screen coordinates: +X right, +Y down. Depth 0 is near,
// depth 1 is far. This reference starts AFTER a camera's projection/clipping.
struct ScreenVertex { double x{}, y{}, depth{}; Color color; };
struct Triangle { std::array<ScreenVertex, 3> vertices; };
struct RasterScene {
    std::uint32_t width{}, height{};
    Color background;
    std::vector<Triangle> triangles;
};
inline constexpr std::size_t max_triangles = 64;
inline constexpr std::size_t max_raster_work = 16'777'216;
inline constexpr double max_screen_coordinate = 8192;

[[nodiscard]] RasterScene demo_raster_scene();
[[nodiscard]] std::expected<void, Error> validate_raster_scene(const RasterScene& scene);
[[nodiscard]] std::expected<Image, Error> rasterize(const RasterScene& scene);

} // namespace prism

This is the file included with the course. Copy and download give you its complete source.

Taking your work offline? Download all course companions