cf_make_custom_shape¶
Category: draw
GitHub: cute_draw.h
Registers a custom SDF shape with the renderer.
| Parameters | Description |
|---|---|
sdf_src |
GLSL snippet defining float sdf(vec2 p, ShapeParams s). |
Return Value¶
A handle to draw with via cf_draw_custom_shape or cf_draw_custom_shape_fill. A zero id means registration failed (compile error, or unsupported backend).
Remarks¶
The snippet defines a signed field over world-space point p: negative inside, positive
outside, and zero on the shape's surface. A true distance is the natural choice, but any
field whose zero crossing is the shape works -- warped, scaled, smoothly blended, or
metaball-style fields included. ShapeParams carries
the 16 floats passed at draw time as eight vec2s named a through h, plus a
vec4 attributes from cf_draw_push_vertex_attributes. The builtin distance helpers
(distance_box, distance_segment, distance_triangle, distance_polygon,
distance_arrow) are available, so most shapes are a few min/max combinators:
// params: a = center, b.x = radius
float sdf(vec2 p, ShapeParams s)
{
return length(p - s.a) - s.b.x;
}
The edge is antialiased from the field's local slope, so it stays one aa width wide whatever the field's scale. Stroke thickness is measured the same way, which is accurate for strokes thin relative to the field's curvature. The renderer culls custom shapes only by the bounds passed at draw time, which must contain the whole shape. All registered shapes batch together with builtin shapes, sprites, and text -- no extra draw calls or pipeline switches. Antialiasing, stroked outlines, colors, and all draw state apply automatically.
Register shapes once at init time (each registration recompiles the renderer's internal shaders), and before creating any custom draw shaders. Requires runtime shader compilation and a compute-capable backend.
Related Pages¶
CF_CustomShape
cf_draw_custom_shape
cf_draw_custom_shape_fill
cf_draw_push_vertex_attributes