App¶
Overview¶
-
class App¶
Main class for the
omdiapplication.The
omdi::Appclass owns the main GLFW window and integrates the ImGui context. It manages the main render loop and provides a simple interface to:initialize the application with an
omdi::Stateinstance,optionally register managers and UI components,
run a render loop with a user-provided rendering callback,
access the underlying GLFW window, ImGui IO, and GLSL version string.
Usage example¶
Basic setup and render loop:
auto state = omdi::State();
// Construct the application window
auto app = omdi::App(&state, "omdi Example", /*swapInterval=*/1, /*isResizable=*/true);
// Initialize managers if needed (empty by default)
app.Init(&state);
// Main loop
app.Render(&state, [&]() {
// Simple render callback
});
Public interface¶
Constructor and destructor¶
-
App::App(omdi::state::State *state, const std::string &name = "omdi App", int swapInterval = 1, bool isResizable = true)¶
Construct the main application object and create the underlying window.
- Parameters:
state – Pointer to the global state manager.
name – Window title (defaults to
"omdi App").swapInterval – Swap interval for VSync (typically
0or1).isResizable – Whether the window is resizable by the user.
The constructor is responsible for setting up GLFW, the window, ImGui context, and any required graphics state.
Main loop helpers¶
-
void App::processInput()¶
Process user input events.
Typically polls GLFW (keyboard, mouse, window events) and updates internal state / ImGui IO accordingly. Should be called once per frame.
-
bool App::startFrame()¶
Begin a new frame.
Prepares ImGui and any rendering state for a new frame.
- Returns:
trueif the frame should proceed,falseif the application is shutting down or the window should close.
-
void App::renderFrame()¶
Render the current frame.
Issues drawing commands for ImGui and any additional application rendering. This is usually called between
omdi::App::startFrame()andomdi::App::endFrame().
-
void App::endFrame(int &width, int &height, ImVec4 &clear_color)¶
Finalize the current frame and present it to the screen.
- Parameters:
width – Output parameter receiving the current framebuffer width.
height – Output parameter receiving the current framebuffer height.
clear_color – Clear color used for the frame; may be read or updated.
This function typically handles buffer swapping and any per-frame housekeeping related to the window size and clear color.
Initialization and render loop¶
-
void App::Init(omdi::state::State *state, const std::map<std::string, void*> &managers = {})¶
Initialize the omdi application with the given state and optional managers.
- Parameters:
state – Pointer to the global state manager.
managers – Map of optional omdi managers, keyed by string identifiers. The exact types pointed to by the values are application-specific.
This function can be used to register subsystems (e.g. logging, resource managers, backends) that the application and UI components can access through the shared
omdi::state::Stateor other mechanisms.
-
void App::Render(omdi::state::State *state, const std::function<void()> &custom_render = nullptr, const std::map<std::string, void*> &components = {}, const std::map<std::string, void*> &managers = {})¶
Run the main render loop using the provided state, optional custom render callback, UI components, and managers.
- Parameters:
state – Pointer to the global state manager.
custom_render – User-provided callback invoked each frame to perform custom rendering (e.g. ImGui windows, scene drawing). If
nullptr, only the built-in omdi components/managers are rendered.components – Map of optional omdi UI components, keyed by string identifiers.
managers – Map of optional omdi managers, keyed by string identifiers.
Internally,
omdi::App::Render()typically loops untilomdi::App::windowShouldClose()returns non-zero, callingomdi::App::processInput(),omdi::App::startFrame(), the custom_render callback (if provided),omdi::App::renderFrame(), andomdi::App::endFrame()each frame.
Window and context accessors¶
-
int App::windowShouldClose() const¶
Check whether the window should close.
- Returns:
Non-zero if the user requested to close the window (e.g. via the window close button), zero otherwise.
This is a thin wrapper around
glfwWindowShouldClose().
-
GLFWwindow *App::window() const¶
Get the underlying GLFW window handle.
- Returns:
Pointer to the
GLFWwindowowned by the application.
This may be useful for low-level integration with other libraries that operate directly on the GLFW window.
Notes¶
omdi::Appassumes that GLFW and ImGui are available and correctly configured in your build environment.The
omdi::App::Render()method is the main entry point for running the application’s render loop; for more advanced control, you can instead write your own loop usingomdi::App::processInput(),omdi::App::startFrame(),omdi::App::renderFrame(), andomdi::App::endFrame()directly.