andyborrell / imgui_tex_inspect

A texture inspector tool for Dear ImGui
MIT License
85 stars 18 forks source link

ImGuiTexInspect

ImGuiTexInspect is a texture inspector library for Dear ImGui. It's a debug tool that allows you to easily inspect the data in any texture. It provides the following features:

Screenshot

screenshot1

Demo

The examples directory contains example projects for the supported platforms. Note that the example projects expect the imgui directory to be in the same parent directory as imgui_tex_inspect.

You can also see a WebGL build of the demo project here

screenshot2

Usage

Add an inspector instance to a Dear ImGui window like so:

ImGui::Begin("Simple Texture Inspector");
ImGuiTexInspect::BeginInspectorPanel("Inspector", textureHandle, textureSize);
ImGuiTexInspect::EndInspectorPanel();
ImGui::End();

Adding annotations to a texture is done by inserting a call to ImGuiTexInspect::DrawAnnotations between the calls to ImGuiTexInspect::BeginInspectorPanel and ImGuiTexInspect::EndInspectorPanel. The following shows how to add text to the inspector showing the RGBA components for each texel. Of course, this per-texel annotation is only visible when sufficiently zoomed in.

ImGui::Begin("Example Texture##screenshot2");
ImGuiTexInspect::BeginInspectorPanel("Inspector", textureHandle, textureSize);
ImGuiTexInspect::DrawAnnotations(ImGuiTexInspect::ValueText(ImGuiTexInspect::ValueText::Floats));
ImGuiTexInspect::EndInspectorPanel();
ImGui::End();

For more advanced usage take a look at imgui_tex_inspect_demo.cpp.

Integration

To integrate ImGuiTexInspect to your project you must:

The following calls are required to initialize ImGuiTexInspect:

ImGuiTexInspect::ImplOpenGL3_Init(); // Or DirectX 11 equivalent (check your chosen backend header file)
ImGuiTexInspect::Init();
ImGuiTexInspect::CreateContext();

The main API is in imgui_tex_inspect.h

In order to initialize the backend you will also need to include the appropriate backend header file, e.g. tex_inspect_opengl.h

Supported Renderers ===== ImGuiTexInspect relies on a renderer specific backend, much like Dear ImGui does. In fact the backend code for ImGuiTexInspect is very closely based on Dear ImGui's own backend code. Currently the following backend source files are available:

To avoid linker errors be sure to only include one backend source file.

Dependencies

The only external dependency is Dear ImGui itself. Dear ImGui version 1.80 onwards is supported. Older versions of Dear ImGui have not been tested, but could probably be made to work without too much effort.