Skip to main content

Overview

ImDrawList is the low-level list of polygons that ImGui functions are filling. At the end of each frame, all command lists are passed to your rendering function. You can use ImGui::GetWindowDrawList() to access the current window’s draw list and add custom primitives.
You can interleave normal ImGui calls and adding primitives to the current draw list.

Getting a Draw List

GetWindowDrawList

Get draw list associated to the current window, to append your own drawing primitives.
ImDrawList*
Pointer to the current window’s draw list
Example:

Structure

ImVector<ImDrawCmd>
Draw commands. Typically 1 command = 1 GPU draw call (unless it’s a callback).
ImVector<ImDrawIdx>
Index buffer. Each command consumes ImDrawCmd::ElemCount of these.
ImVector<ImDrawVert>
Vertex buffer.
ImDrawListFlags
Flags controlling anti-aliasing and other rendering options.

Clipping

PushClipRect

Render-level scissoring. This is passed down to your render function but not used for CPU-side coarse clipping.
const ImVec2&
Top-left corner of clipping rectangle
const ImVec2&
Bottom-right corner of clipping rectangle
bool
default:"false"
If true, intersect with current clip rect instead of replacing it
Prefer using higher-level ImGui::PushClipRect() to affect logic (hit-testing and widget culling).

PopClipRect

Restore previous clipping rectangle.

PushClipRectFullScreen

Set clipping rectangle to full screen.

Texture Management

PushTexture

Set texture for subsequent drawing commands.
ImTextureRef
Texture reference to use

PopTexture

Restore previous texture.

Primitive Shapes

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

AddLine

Draw a line between two points.
const ImVec2&
Start point
const ImVec2&
End point
ImU32
Color (use IM_COL32(r, g, b, a) macro)
float
default:"1.0f"
Line thickness in pixels
Example:

AddRect

Draw a rectangle outline.
const ImVec2&
Top-left corner
const ImVec2&
Bottom-right corner
ImU32
Color
float
default:"0.0f"
Corner rounding radius
ImDrawFlags
default:"0"
Flags for corner rounding (e.g., ImDrawFlags_RoundCornersTopLeft)
float
default:"1.0f"
Border thickness

AddRectFilled

Draw a filled rectangle. Example:

AddRectFilledMultiColor

Draw a filled rectangle with different colors at each corner (gradient).
ImU32
Top-left corner color
ImU32
Top-right corner color
ImU32
Bottom-right corner color
ImU32
Bottom-left corner color

AddQuad / AddQuadFilled

Draw a quadrilateral (4-sided polygon).

AddTriangle / AddTriangleFilled

Draw a triangle.

AddCircle / AddCircleFilled

Draw a circle.
const ImVec2&
Center point
float
Circle radius
ImU32
Color
int
default:"0"
Number of segments (0 = auto-calculate based on radius)
Use num_segments = 0 to automatically calculate tessellation (preferred).
Example:

AddNgon / AddNgonFilled

Draw a regular polygon with specified number of sides.
int
Number of sides (e.g., 5 for pentagon, 6 for hexagon)

AddEllipse / AddEllipseFilled

Draw an ellipse.
const ImVec2&
Radius on X and Y axes
float
default:"0.0f"
Rotation in radians

Text

AddText

Draw text at specified position.
const ImVec2&
Text position (top-left)
ImU32
Text color
const char*
Start of text string
const char*
End of text string (NULL for null-terminated)
ImFont*
Font to use (extended version)
float
Font size (extended version)

Curves

AddBezierCubic

Draw a cubic Bezier curve (4 control points).
const ImVec2&
Start point
const ImVec2&
First control point
const ImVec2&
Second control point
const ImVec2&
End point

AddBezierQuadratic

Draw a quadratic Bezier curve (3 control points).

See Also