feat: add stb dependency and window::screenshot()

Added deps/Findstb.cmake (fetches stb via FetchContent, provides
stb::stb interface target).

Linked to cbt_opengl. Implemented window::screenshot() using
glReadPixels + vertical flip + stb_image_write to save RGBA PNG.

Press S in the app to capture current frame (saved as
screenshot.png). Updated help text.

(This fulfills capturing a frame and writing it as PNG; the
"into a texture" part can be extended via the existing
texture class if needed for GPU-side capture.)
This commit is contained in:
2026-05-05 23:48:05 +02:00
parent c3860cc1d3
commit 4a88c8cc06
5 changed files with 94 additions and 76 deletions
+4
View File
@@ -22,6 +22,7 @@ auto main(int argc, char const* argv[]) -> int {
if (arg == "--help" || arg == "-h") {
fmt::print("Usage: {} [--duration <seconds>] [--help|-h]\n", argv[0]);
fmt::print(" --duration <seconds> Auto-terminate after N seconds (for testing/CI)\n");
fmt::print(" S key Take screenshot (saved as screenshot.png)\n");
return 0;
}
if (arg == "--duration" && i + 1 < argc) {
@@ -80,6 +81,9 @@ auto main(int argc, char const* argv[]) -> int {
if (glfwGetKey(win.raw(), GLFW_KEY_Q) == GLFW_PRESS) {
win.stop();
}
if (glfwGetKey(win.raw(), GLFW_KEY_S) == GLFW_PRESS) {
win.screenshot();
}
auto now = std::chrono::steady_clock::now();
auto dt = std::chrono::duration<float>(now - prev).count();