Added orx-no-clear

This commit is contained in:
edwin
2018-11-06 15:44:49 +01:00
parent 07598fdbbe
commit 7cec4bddc8
6 changed files with 495 additions and 429 deletions

21
orx-no-clear/README.md Normal file
View File

@@ -0,0 +1,21 @@
# orx-no-clear
A simple OPENRNDR Extension that provides the classical drawing-without-clearing-the-screen functionality that
OPENRNDR does not support natively.
#### Usage
```
class NoClearProgram: Program() {
override fun setup() {
backgroundColor = ColorRGBa.PINK
extend(NoClear())
}
override fun draw() {
drawer.circle(Math.cos(seconds) * width / 2.0 + width / 2.0, Math.sin(seconds * 0.24) * height / 2.0 + height / 2.0, 20.0)
}
}
```

View File

@@ -0,0 +1,45 @@
import org.openrndr.Extension
import org.openrndr.Program
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.Drawer
import org.openrndr.draw.RenderTarget
import org.openrndr.draw.isolated
import org.openrndr.draw.renderTarget
class NoClear : Extension {
override var enabled: Boolean = true
private var renderTarget: RenderTarget? = null
override fun beforeDraw(drawer: Drawer, program: Program) {
if (renderTarget == null || renderTarget?.width != program.width || renderTarget?.height != program.height) {
renderTarget?.let {
it.colorBuffer(0).destroy()
it.detachColorBuffers()
it.destroy()
}
renderTarget = renderTarget(program.width, program.height) {
colorBuffer()
depthBuffer()
}
renderTarget?.let {
drawer.withTarget(it) {
background(program.backgroundColor ?: ColorRGBa.TRANSPARENT)
}
}
}
renderTarget?.bind()
}
override fun afterDraw(drawer: Drawer, program: Program) {
renderTarget?.unbind()
renderTarget?.let {
drawer.isolated {
drawer.ortho()
drawer.image(it.colorBuffer(0))
}
}
}
}