The NoClear extension

Creative coding frameworks have two different defaults: either they clear the screen before each animation frame or they don’t. OPENRNDR belongs to the first group.

Switching to “draw-without-clearing-the-screen” can be useful to produce complex designs with simple programs.

It is also how pen and paper seems to work: we add ink to the paper and the previous ink does not disappear.

Such behavior can easily be enabled by adding extend(NoClear()) to our programs.
Here an example that draws circles at the current mouse position:

fun main() = application {
    program {
        backgroundColor = ColorRGBa.PINK
        extend(NoClear())
        extend {
            drawer.circle(mouse.position, 20.0)
        }
    }
}

../media/orx-no-clear-001.png

Without NoClear only one circle would be visible at the current mouse location.

Configurable properties

orx-no-clear provides configurable properties:

  • A multisample value can be passed in the constructor. The default value is BufferMultisample.Disabled. For smoother rendering we can construct it like this: NoClear(BufferMultisample.SampleCount(8)). Different graphic cards may accept higher or lower values.
  • Use backdrop to specify the initial state of the buffer. You could clear the background to a specific color, display a loaded image, or draw anything else.
  • Use colorType to change the default UINT8 color type to something else, for instance FLOAT32 for finer color precision.

Find the orx-no-clear source code and examples featuring the available properties in GitHub.

edit on GitHub


This site uses Just the Docs, a documentation theme for Jekyll.