feat: add --scene and --screenshot CLI flags
Added --scene <cube|sphere> to select the initial scene from the command line (useful for headless/CI testing where key presses aren't possible). Added --screenshot to render a single frame, save a PNG, and exit immediately. Combined with --duration or used alone, this allows fully automated screenshot capture without relying on interactive key presses. Updated help text to reflect new options.
This commit is contained in:
@@ -17,12 +17,16 @@
|
||||
|
||||
auto main(int argc, char const* argv[]) -> int {
|
||||
float max_duration_seconds = 0.0f;
|
||||
std::string_view scene_name = "cube";
|
||||
bool take_screenshot = false;
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
std::string_view arg = argv[i];
|
||||
if (arg == "--help" || arg == "-h") {
|
||||
fmt::print("Usage: {} [--duration <seconds>] [--help|-h]\n", argv[0]);
|
||||
fmt::print("Usage: {} [options]\n", argv[0]);
|
||||
fmt::print(" --duration <seconds> Auto-terminate after N seconds (for testing/CI)\n");
|
||||
fmt::print(" --scene <cube|sphere> Select initial scene (default: cube)\n");
|
||||
fmt::print(" --screenshot Render one frame, save screenshot, and exit\n");
|
||||
fmt::print(" S key Take screenshot (saved as screenshot.png)\n");
|
||||
fmt::print(" 1/2 key Switch between cube/sphere scene\n");
|
||||
return 0;
|
||||
@@ -31,6 +35,14 @@ auto main(int argc, char const* argv[]) -> int {
|
||||
max_duration_seconds = std::stof(std::string(argv[++i]));
|
||||
continue;
|
||||
}
|
||||
if (arg == "--scene" && i + 1 < argc) {
|
||||
scene_name = argv[++i];
|
||||
continue;
|
||||
}
|
||||
if (arg == "--screenshot") {
|
||||
take_screenshot = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
auto win = cbt::window("cuber", 1280, 720);
|
||||
@@ -52,7 +64,11 @@ auto main(int argc, char const* argv[]) -> int {
|
||||
if (!cube_scn.init() || !sphere_scn.init()) {
|
||||
return 1;
|
||||
}
|
||||
active_scene = &cube_scn;
|
||||
if (scene_name == "sphere" || scene_name == "2") {
|
||||
active_scene = &sphere_scn;
|
||||
} else {
|
||||
active_scene = &cube_scn;
|
||||
}
|
||||
|
||||
// signal handling + optional duration timer (via ASIO)
|
||||
asio::io_context io;
|
||||
@@ -106,6 +122,11 @@ auto main(int argc, char const* argv[]) -> int {
|
||||
|
||||
win.swap_buffers();
|
||||
win.poll_events();
|
||||
|
||||
if (take_screenshot) {
|
||||
win.screenshot();
|
||||
win.stop();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user