class SFML::StencilMode

How a draw call interacts with the stencil buffer. The classic use is masking β€” first you draw a β€œmask” shape that writes a value into the stencil buffer, then you draw the masked content with a comparison that only lets pixels through where the stencil matches.

target.clear(SFML::Color.black, stencil: 0)

# Phase 1 β€” write the mask shape into the stencil buffer. write = SFML::StencilMode.new( comparison: :always, update_operation: :replace, reference: 1, only_write_mask: true, # don’t actually paint colour ) target.draw(mask_circle, stencil_mode: write)

# Phase 2 β€” draw the content; only pixels where stencil == 1 # survive. read = SFML::StencilMode.new( comparison: :equal, update_operation: :keep, reference: 1, ) target.draw(scene, stencil_mode: read)

stencilOnly (only_write_mask:) is a niche flag β€” set it to true on the mask-write pass if you don’t want the mask shape itself to be visible in the colour buffer.