Frame Lifecycle
The typical Dear ImGui frame consists of:- NewFrame() - Start a new frame, process input
- UI Code - Build your user interface
- Render() - Finalize draw data
- GetDrawData() - Retrieve draw commands
- Backend Rendering - Submit to graphics API
NewFrame
Starts a new Dear ImGui frame. Call this at the beginning of each frame before submitting any UI commands.Description
This function:- Processes input from
ImGuiIO(mouse, keyboard, gamepad) - Updates internal state and timing
- Prepares for new UI commands
- Clears the previous frame’s data
Example
Always call your backend’s
NewFrame() functions (e.g., ImGui_ImplGlfw_NewFrame()) before calling ImGui::NewFrame().EndFrame
Ends the Dear ImGui frame. Automatically called byRender(), but can be called manually if you want to skip rendering.
Description
This function:- Finalizes the current frame’s state
- Updates window positions and sizes
- Handles end-of-frame operations
Example
Render
Ends the Dear ImGui frame and finalizes draw data. Call this after submitting all UI commands.Description
This function:- Calls
EndFrame()internally - Finalizes all draw lists
- Prepares
ImDrawDatafor rendering - Sorts draw commands by texture and layer
Example
You must call
Render() before calling GetDrawData(). The draw data is only valid after finalization.GetDrawData
Retrieves the draw data generated by the current frame. Pass this to your rendering backend.Returns
ImDrawData*
Pointer to the draw data structure containing all draw commands for the frame. Returns NULL if
Render() hasn’t been called yet.Description
The returnedImDrawData contains:
- All draw commands organized by command lists
- Vertex and index buffers
- Texture bindings
- Clipping rectangles
- Display position and size