Modern C++ GUI: Debug Tools & Dashboards with Dear ImGui [#36-1]
이 글의 핵심
Build lightweight in-engine debug UIs with Dear ImGui: immediate mode, backends, and pitfalls.
Introduction: beyond printf—visible state
Dear ImGui is an immediate-mode GUI library: every frame you call widgets; interaction is returned from those calls. It is small, easy to integrate, and ideal for in-engine overlays, profilers, and tuning panels.
Covers: what ImGui is, minimal window flow, GLFW+OpenGL backends, debugging dashboards, common crashes (frame order, local state), best practices, production notes.
Table of contents
- What is Dear ImGui?
- Immediate mode
- Minimal example
- Backend (GLFW + OpenGL)
- Complete example
- Dashboards
- Common errors
- Best practices
- Production patterns
1. What is Dear ImGui?
Header-friendly, minimal dependencies, backends for GLFW/SDL/DX/Vulkan/Metal. Best for tools inside an engine—not full desktop app frameworks like Qt for every case.
flowchart TB
subgraph app["App"]
loop["Main loop"]
ui["ImGui Begin…End"]
end
subgraph imgui["Dear ImGui"]
core["imgui core"]
backend["impl_* backends"]
end
loop --> ui --> core --> backend
2. Immediate mode vs retained UI
Retained toolkits build widget objects and fire callbacks; ImGui redraws widgets each frame and uses return values (if (Button(...))).
3. Minimal frame order
Backend NewFrame → ImGui::NewFrame → Begin/End widgets → ImGui::Render → Backend RenderDrawData
Critical: slider/state must live in static or member storage—not fresh locals reset every frame.
4. GLFW + OpenGL
Clone official examples (example_glfw_opengl3), copy backend sources, initialize context, and run the loop—the full main.cpp listing below ties the steps together.
5. Complete example
The full main_imgui_minimal.cpp example includes PlotLines, buttons, and a second window—keep comments in your team’s language in your repo copy.
6. Dashboards
Bind ServerStats fields to Text, PlotLines, and buttons for live ops panels.
7. Common errors
NewFrame/Renderordering wrong → blank UI or crash.- Missing backend init → no input / black screen.
- Widgets only called once behind a flag → UI disappears (ImGui needs every frame).
SliderFloaton a stack local → value resets.
8. Best practices
PushID/##suffix to avoid ID clashes; CollapsingHeader for sections; tooltips; keep style setup in one place.
9. Production patterns
ImGui is not thread-safe—call only from the main thread; pass stats via queues. Docking/viewports optional. Handle GPU errors from backends explicitly.
Keywords
Dear ImGui tutorial, immediate mode GUI, GLFW ImGui, OpenGL debug UI, C++ dashboard
Next: Qt basics (#36-2)
Previous: Wasm (#35-2)