diff --git a/cuber.cpp b/cuber.cpp index 933c52a..9700c57 100644 --- a/cuber.cpp +++ b/cuber.cpp @@ -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 ] [--help|-h]\n", argv[0]); + fmt::print("Usage: {} [options]\n", argv[0]); fmt::print(" --duration Auto-terminate after N seconds (for testing/CI)\n"); + fmt::print(" --scene 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;