Skip to main content
These functions form the backbone of the Dear ImGui render loop. Call them in sequence each frame to process input, build your UI, and generate draw commands for rendering.

Frame Lifecycle

The typical Dear ImGui frame consists of:
  1. NewFrame() - Start a new frame, process input
  2. UI Code - Build your user interface
  3. Render() - Finalize draw data
  4. GetDrawData() - Retrieve draw commands
  5. 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 by Render(), 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
If you call EndFrame() without rendering, you’ll waste CPU cycles. It’s better to not create any windows and skip NewFrame() entirely if you don’t need to render.

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 ImDrawData for 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 returned ImDrawData contains:
  • All draw commands organized by command lists
  • Vertex and index buffers
  • Texture bindings
  • Clipping rectangles
  • Display position and size

Example

Validation

The draw data is only valid until the next call to NewFrame(). Don’t cache this pointer across frames.

Complete Example