Skip to main content

Drawing API (ImDrawList)

The ImDrawList API provides low-level access to Dear ImGui’s rendering system, allowing you to draw custom shapes, lines, text, and complex graphics primitives.

Overview

ImDrawList is a draw command list that holds rendering instructions. Each window has its own ImDrawList, and you can also get background and foreground draw lists for global rendering.

Getting a Draw List

Basic Shapes

Lines

Draw lines between two points:
Function signature:

Rectangles

Draw outlined or filled rectangles:
Function signatures:

Circles and Ellipses

Draw circular and elliptical shapes:
Function signatures:
Using num_segments = 0 automatically calculates the optimal number of segments based on the radius. This is the recommended approach.

Triangles and Polygons

Text Rendering

Draw text at specific positions:
Function signatures:

Path API

The path API allows you to build complex shapes by accumulating points:
Path functions:

Bezier Curves

Image Rendering

Clipping

Clip rendering to specific regions:

Color Helpers

Complete Example

Filled shapes must use clockwise winding order. The anti-aliasing fringe depends on it. Counter-clockwise shapes will have inward anti-aliasing.

Reference

  • ImDrawList source code (line 3268)
  • See imgui_demo.cpp for extensive examples
  • For rectangular primitives, p_min represents upper-left and p_max represents lower-right corners