#pragma once #include "hd2d/GL.h" #include "hd2d/RenderTarget.h" #include namespace hd2d { // Writes color attachment 0 of `fbo` as PNG; `fbo` = 0 reads the window's // backbuffer (call before swapBuffers). bool saveScreenshot(const std::string& path, int width, int height, GLuint fbo = 0); // Window-independent render output for headless captures. Color is plain // RGBA8 (not sRGB) plus a depth/stencil buffer, matching the default // framebuffer, so captures are pixel-identical to on-screen frames. // // hd2d::Window window; window.create(w, h, "capture", false, false, /*visible*/ false); // hd2d::OffscreenTarget out; out.create(window.width(), window.height()); // renderer.setOutputFramebuffer(out.fbo()); // renderer.render(scene, cam, time); // + any ImGui / UI drawing // out.save("shot.png"); class OffscreenTarget { public: bool create(int width, int height); void resize(int width, int height); // reallocates only when the size changes GLuint fbo() const { return target_.fbo(); } GLuint color() const { return target_.color(); } int width() const { return target_.width(); } int height() const { return target_.height(); } bool save(const std::string& path) const { return saveScreenshot(path, width(), height(), fbo()); } private: RenderTarget target_; }; } // namespace hd2d