Skip to main content

ImGuiGlfwOpenGLBackend Class

ImGui backend for GLFW windowing and OpenGL 4.1 rendering. More...

Declaration

class helios::imgui::ImGuiGlfwOpenGLBackend { ... }

Base class

classImGuiBackend

Platform-agnostic interface for ImGui backend implementations. More...

Public Constructors Index

ImGuiGlfwOpenGLBackend (const ImGuiGlfwOpenGLBackend &)=delete
ImGuiGlfwOpenGLBackend (ImGuiGlfwOpenGLBackend &&other) noexcept=delete
ImGuiGlfwOpenGLBackend (WindowHandle window, PlatformWorld &platformWorld)

Constructs the ImGui backend for GLFW+OpenGL. More...

Public Destructor Index

~ImGuiGlfwOpenGLBackend () override

Destructor; shuts down ImGui backend and releases resources. More...

Public Operators Index

ImGuiGlfwOpenGLBackend &operator= (const ImGuiGlfwOpenGLBackend &)=delete
ImGuiGlfwOpenGLBackend &operator= (ImGuiGlfwOpenGLBackend &&other) noexcept=delete

Public Member Functions Index

voidrenderDrawData (ImDrawData *drawData) override

Renders ImGui draw data using OpenGL. More...

boolnewFrame () override

Starts a new ImGui frame. More...

Private Member Functions Index

voidshutdown () noexcept

Shuts down the ImGui GLFW and OpenGL backend. More...

boolinitialize () noexcept

Performs one-time backend initialization. More...

Private Member Attributes Index

boolinitialized_ = false

Indicates whether the backend has been successfully initialized. More...

WindowHandlewindowHandle_

Window entity handle used to resolve the native GLFW window. More...

PlatformWorld &platformWorld_

Platform world that stores the GLFW window-handle component. More...

Description

ImGui backend for GLFW windowing and OpenGL 4.1 rendering.

Initializes ImGui context, GLFW platform layer, and OpenGL renderer. This backend is non-copyable and non-movable due to resource ownership semantics.

info

Only one instance should exist per application. Creating multiple instances will throw a std::runtime_error.

Definition at line 37 of file ImGuiGlfwOpenGLBackend.ixx.

Public Constructors

ImGuiGlfwOpenGLBackend()

helios::imgui::ImGuiGlfwOpenGLBackend::ImGuiGlfwOpenGLBackend (const ImGuiGlfwOpenGLBackend &)
delete

Definition at line 127 of file ImGuiGlfwOpenGLBackend.ixx.

ImGuiGlfwOpenGLBackend()

helios::imgui::ImGuiGlfwOpenGLBackend::ImGuiGlfwOpenGLBackend (ImGuiGlfwOpenGLBackend && other)
noexcept delete

Definition at line 129 of file ImGuiGlfwOpenGLBackend.ixx.

ImGuiGlfwOpenGLBackend()

helios::imgui::ImGuiGlfwOpenGLBackend::ImGuiGlfwOpenGLBackend (WindowHandle window, PlatformWorld & platformWorld)
inline explicit

Constructs the ImGui backend for GLFW+OpenGL.

Parameters
window

GLFW window handle. Must be valid for the lifetime of this backend.

platformWorld

Platform world used to resolve the native GLFW window handle.

Exceptions
std::runtime_error

if an ImGui context already exists.

Definition at line 140 of file ImGuiGlfwOpenGLBackend.ixx.

140 explicit ImGuiGlfwOpenGLBackend(WindowHandle window, PlatformWorld& platformWorld)
141 : windowHandle_(window), platformWorld_(platformWorld) {
142
143 if (ImGui::GetCurrentContext()) {
144 throw std::runtime_error("ImGui context already initialized");
145 }
146
147 IMGUI_CHECKVERSION();
148 ImGui::CreateContext();
149 ImGuiIO& io = ImGui::GetIO();
150 io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
151 io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
152
153 ImGui::StyleColorsDark();
154 }

Public Destructor

~ImGuiGlfwOpenGLBackend()

helios::imgui::ImGuiGlfwOpenGLBackend::~ImGuiGlfwOpenGLBackend ()
inline

Destructor; shuts down ImGui backend and releases resources.

See Also

shutdown()

Definition at line 193 of file ImGuiGlfwOpenGLBackend.ixx.

194 shutdown();
195 }

Public Operators

operator=()

ImGuiGlfwOpenGLBackend & helios::imgui::ImGuiGlfwOpenGLBackend::operator= (const ImGuiGlfwOpenGLBackend &)
delete

Definition at line 128 of file ImGuiGlfwOpenGLBackend.ixx.

operator=()

ImGuiGlfwOpenGLBackend & helios::imgui::ImGuiGlfwOpenGLBackend::operator= (ImGuiGlfwOpenGLBackend && other)
noexcept delete

Definition at line 130 of file ImGuiGlfwOpenGLBackend.ixx.

Public Member Functions

newFrame()

bool helios::imgui::ImGuiGlfwOpenGLBackend::newFrame ()
inline virtual

Starts a new ImGui frame.

Returns

true if frame setup succeeded; otherwise false.

Definition at line 174 of file ImGuiGlfwOpenGLBackend.ixx.

174 bool newFrame() override {
175
176 if (!initialize()) {
177 return false;
178 }
179
180
181 ImGui_ImplOpenGL3_NewFrame();
182 ImGui_ImplGlfw_NewFrame();
183 ImGui::NewFrame();
184
185 return true;
186 }

renderDrawData()

void helios::imgui::ImGuiGlfwOpenGLBackend::renderDrawData (ImDrawData * drawData)
inline virtual

Renders ImGui draw data using OpenGL.

Parameters
drawData

Pointer to ImGui draw data.

info

If the backend is not initialized yet, this call is a no-op.

Definition at line 163 of file ImGuiGlfwOpenGLBackend.ixx.

163 void renderDrawData(ImDrawData* drawData) override {
164 if (initialized_) {
165 ImGui_ImplOpenGL3_RenderDrawData(drawData);
166 }
167 }

Private Member Functions

initialize()

bool helios::imgui::ImGuiGlfwOpenGLBackend::initialize ()
inline noexcept

Performs one-time backend initialization.

Resolves the GLFW window entity, initializes the ImGui GLFW binding, and initializes the OpenGL renderer backend.

Returns

true if the backend is initialized and ready; otherwise false.

Definition at line 90 of file ImGuiGlfwOpenGLBackend.ixx.

90 bool initialize() noexcept {
91
92 if (initialized_) {
93 return true;
94 }
95 auto glfwWindow = platformWorld_.findEntity(windowHandle_);
96
97 if (!glfwWindow) {
98 assert(false && "Expected a valid GLFW window entity");
99 return false;
100 }
101
102 auto glfwComp = glfwWindow->get<GLFWWindowHandleComponent<WindowHandle>>();
103
104 if (!glfwComp) {
105 return false;
106 }
107
108 if (!ImGui_ImplGlfw_InitForOpenGL(glfwComp->handle, true)) {
109 ImGui::DestroyContext();
110 assert(false && "Failed to initialize GLFW backend for ImGui");
111 return false;
112 }
113
114 if (!ImGui_ImplOpenGL3_Init("#version 410")) {
115 ImGui_ImplGlfw_Shutdown();
116 ImGui::DestroyContext();
117 assert(false && "Failed to initialize OpenGL 4.1 backend for ImGui");
118 return false;
119 }
120 initialized_ = true;
121 return true;
122 }

shutdown()

void helios::imgui::ImGuiGlfwOpenGLBackend::shutdown ()
inline noexcept

Shuts down the ImGui GLFW and OpenGL backend.

Ensures proper cleanup of the ImGui context, OpenGL, and GLFW resources. After calling this method, the backend will no longer be initialized, and associated resources will be released.

This function is safe to call multiple times but has no effect if the backend is not currently initialized.

info

This method is noexcept and will not throw exceptions.

Definition at line 63 of file ImGuiGlfwOpenGLBackend.ixx.

63 void shutdown() noexcept {
64 if (initialized_) {
65 ImGui_ImplOpenGL3_Shutdown();
66 ImGui_ImplGlfw_Shutdown();
67 ImGui::DestroyContext();
68 initialized_ = false;
69 }
70 }

Private Member Attributes

initialized_

bool helios::imgui::ImGuiGlfwOpenGLBackend::initialized_ = false

Indicates whether the backend has been successfully initialized.

Tracks the initialization state of the ImGui backend to prevent multiple redundant initialization attempts and manage proper shutdown procedures.

info

Modified during initialization and shutdown processes.

Definition at line 49 of file ImGuiGlfwOpenGLBackend.ixx.

49 bool initialized_ = false;

platformWorld_

PlatformWorld& helios::imgui::ImGuiGlfwOpenGLBackend::platformWorld_

Platform world that stores the GLFW window-handle component.

Definition at line 80 of file ImGuiGlfwOpenGLBackend.ixx.

80 PlatformWorld& platformWorld_;

windowHandle_

WindowHandle helios::imgui::ImGuiGlfwOpenGLBackend::windowHandle_

Window entity handle used to resolve the native GLFW window.

Definition at line 75 of file ImGuiGlfwOpenGLBackend.ixx.

75 WindowHandle windowHandle_;

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.