Skip to content

Screen and Video Captures

omar edited this page Sep 6, 2022 · 1 revision

Setup

  • Tips: try screenshots before video (simpler as video depend on FFMPEG).
  • Application MUST set test_io.ScreenCaptureFunc to a function to capture framebuffer. Our helpers in shared/imgui_app.cpp have capture functions implemented for OpenGL and DirectX11.
  • Application MUST call ImGuiTestEngine_PostSwap(engine) after swapping all its framebuffers. The TestEngine will then call test_io.ScreenCaptureFunc() as required by active capturing.
  • For video: Application MUST set test_io.VideoCaptureEncoderPath to a FFMPEG executable and test_io.VideoCaptureEncoderParams/test_io.GifCaptureEncoderParams for params.
  • The UI (ImGuiTestEngine_ShowTestEngineWindows() exposes those fields as well as default templates under Options->Screen/Video Capture:

Capture Settings

Usage

Two mode of operation:

  • Interactive: call ImGuiCaptureToolUI::ShowCaptureToolWindow() or access via TestEngine UI under Tools -> Capture Tool.
  • Programmatic: generally via ImGuiTestContext::CaptureXXX functions

Examples of tests performing captures

t = IM_REGISTER_TEST(e, "demo_tests", "capture_screenshot");
t->TestFunc = [](ImGuiTestContext* ctx)
{
    ctx->SetRef("Dear ImGui Demo");
    ctx->ItemOpen("Widgets");       // Open collapsing header
    ctx->ItemOpenAll("Basic");      // Open tree node and all its descendant
    ctx->CaptureScreenshotWindow("Dear ImGui Demo", ImGuiCaptureFlags_StitchAll | ImGuiCaptureFlags_HideMouseCursor);
};

t = IM_REGISTER_TEST(e, "demo_tests", "capture_video");
t->TestFunc = [](ImGuiTestContext* ctx)
{
    ctx->SetRef("Dear ImGui Demo");
    ctx->ItemCloseAll("");
    ctx->MouseTeleportToPos(ctx->GetWindowByRef("")->Pos);

    ImGuiCaptureArgs args;
    ctx->CaptureAddWindow(&args, "Dear ImGui Demo"); // Optional: Capture single window
    ctx->CaptureBeginVideo(&args);
    ctx->ItemOpen("Widgets");
    ctx->ItemInputValue("Basic/input text", "My first video!");
    ctx->CaptureEndVideo(&args);
};
Clone this wiki locally