Skip to main content

ImDrawCmd Structure

Typically, 1 command = 1 GPU draw call (unless it’s a callback).
ImVec4
Clipping rectangle (x1, y1, x2, y2). Subtract ImDrawData->DisplayPos to get clipping rectangle in viewport coordinates.
ImTextureRef
Reference to font/texture atlas or user-provided texture ID.
unsigned int
Start offset in vertex buffer. Always 0 unless ImGuiBackendFlags_RendererHasVtxOffset is enabled.
unsigned int
Number of indices to render (multiple of 3 for triangles).

Polygon Primitives

AddPolyline

Draw a polyline (connected line segments).
const ImVec2*
Array of points
int
Number of points in array
ImU32
Color
ImDrawFlags
Flags (e.g., ImDrawFlags_Closed to close the polyline)
float
Line thickness
Example:

AddConvexPolyFilled

Draw a filled convex polygon. Fast O(N) algorithm.
Only simple polygons are supported (no self-intersections, no holes). Polygon must be convex.

AddConcavePolyFilled

Draw a filled concave polygon. Slower O(N²) algorithm.
Concave polygon fill is more expensive than convex. Only simple polygons are supported (no self-intersections, no holes).

Image Primitives

AddImage

Draw a textured rectangle.
ImTextureRef
Texture reference
const ImVec2&
Top-left corner position
const ImVec2&
Bottom-right corner position
const ImVec2&
default:"(0, 0)"
Top-left UV coordinate
const ImVec2&
default:"(1, 1)"
Bottom-right UV coordinate
ImU32
default:"IM_COL32_WHITE"
Tint color
Using (0,0)->(1,1) texture coordinates will generally display the entire texture.
Example:

AddImageQuad

Draw a textured quadrilateral (allows perspective distortion).
const ImVec2&
Four corner positions
const ImVec2&
UV coordinates for each corner

AddImageRounded

Draw a textured rectangle with rounded corners.
float
Corner rounding radius
ImDrawFlags
Flags to control which corners are rounded

Path API

The path API allows building complex shapes by accumulating points, then rendering them.
Important: Filled shapes must always use clockwise winding order! Counter-clockwise shapes will have “inward” anti-aliasing.

PathClear

Clear the current path (remove all accumulated points).

PathLineTo

Add a point to the current path.
const ImVec2&
Point position

PathLineToMergeDuplicate

Add a point to path only if it’s different from the last point.

PathFillConvex

Fill the current path as a convex polygon and clear the path.
ImU32
Fill color

PathFillConcave

Fill the current path as a concave polygon and clear the path. Slower than PathFillConvex().

PathStroke

Stroke the current path and clear it.
ImU32
Stroke color
ImDrawFlags
Flags (e.g., ImDrawFlags_Closed)
float
default:"1.0f"
Line thickness

Path Arcs

Add arc segments to the path.
const ImVec2&
Arc center
float
Arc radius
float
Start angle in radians
float
End angle in radians
PathArcToFast() uses precomputed angles for a 12-step circle. a_min_of_12 and a_max_of_12 are in range 0-11.

Path Bezier Curves

Add Bezier curve segments to the path. Example - Custom Shape with Path API:

PathRect

Add a rectangle to the path.

Advanced: Draw Callbacks

AddCallback

Add a custom callback to alter render state or emit custom rendering commands.
ImDrawCallback
Function pointer to callback
void*
User data to pass to callback
size_t
default:"0"
Size of data to copy (0 = just copy pointer)
Be mindful of the difference:
  • If userdata_size == 0: Copy/store the pointer as-is
  • If userdata_size > 0: Copy userdata_size bytes into an internal buffer
Example:

AddDrawCmd

Force creation of a new draw call. Useful for dependent rendering / blending. Otherwise primitives are merged into the same draw call.

Channels (Advanced)

Channels allow splitting render into layers that can be drawn out-of-order.
Prefer using your own persistent instance of ImDrawListSplitter instead of the channel functions.

See Also