natiny.render.scissor_begin

Lua
natiny.render.scissor_begin(x, y, width, height [, fn])

Starts a scissor clip rectangle for subsequent draw calls on the currently bound render target.

Parameters

Name Type Default Description
x number Left edge of the clip rectangle
y number Top edge of the clip rectangle
width number Clip rectangle width
height number Clip rectangle height
fn function nil Called with no arguments while the clip is in force; the clip is ended when it returns

Example

Lua
natiny.render.scissor_begin(40, 40, 220, 120, function()
    draw_content()
end)

Without the callback, end the clip by hand:

Lua
natiny.render.scissor_begin(40, 40, 220, 120)
draw_content()
natiny.render.scissor_end()

Notes

  • With fn, the clip is ended when fn returns, including when it raises an error - the error is re-raised afterwards. A skipped scissor_end leaves the stack one level deep for the rest of the frame, and every draw after it clipped to a rectangle nobody asked for.
  • Scissors form a stack. A nested rectangle is intersected with its parent, and callback forms nest the same way.
  • Pair every successful begin with natiny.render.scissor_end(); nesting is limited to 16 levels.