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

Give an image one owner

Owned pixel storage and the renderer and PPM-writing interfaces.

20 lines renderer.hpp
#pragma once
#include "prism/scene.hpp"
#include <span>
#include <filesystem>

namespace prism {

// A value owns the complete RGB image. A span is only a temporary borrowed view.
struct Image {
    std::uint32_t width{}, height{};
    std::vector<std::uint8_t> rgb;
    [[nodiscard]] std::span<const std::uint8_t> pixels() const & noexcept { return rgb; }
    std::span<const std::uint8_t> pixels() const && = delete;
};

[[nodiscard]] std::expected<Image, Error> render(const Scene& scene);
[[nodiscard]] std::expected<void, Error> write_ppm(const std::filesystem::path& path,
                                                    const Image& image);
} // 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