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.
#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
