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

Run the ray renderer

The command-line boundary that builds a demo scene and writes its image.

31 lines main.cpp
#include "prism/renderer.hpp"
#include <exception>
#include <iostream>
#include <string_view>

int main(int argc, char* argv[]) {
    if (argc == 2 && std::string_view{argv[1]} == "--help") {
        std::cout << "Parallax CPU renderer\nUsage: prism-render <output.ppm>\n";
        return 0;
    }
    if (argc != 2) {
        std::cerr << "Usage: prism-render <output.ppm>\n";
        return 1;
    }
    try {
        const auto scene = prism::demo_scene();
        auto image = prism::render(scene);
        if (!image) { std::cerr << image.error().message << '\n'; return 1; }
        if (auto written = prism::write_ppm(std::filesystem::path{argv[1]}, *image); !written) {
            std::cerr << written.error().message << '\n';
            return 1;
        }
        std::cout << "Rendered " << image->width << " × " << image->height << " pixels.\n";
        return 0;
    } catch (const std::exception&) {
        // The CLI is the final exception boundary. Never print arbitrary input.
        std::cerr << "The render could not complete.\n";
        return 1;
    }
}

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

Taking your work offline? Download all course companions