changes
This commit is contained in:
@@ -1,54 +1,54 @@
|
||||
# orx-no-clear
|
||||
|
||||
A simple OPENRNDR Extension that provides the classical drawing-without-clearing-the-screen functionality that
|
||||
OPENRNDR does not support natively.
|
||||
|
||||
#### Usage
|
||||
|
||||
```kotlin
|
||||
fun main() = application {
|
||||
configure {
|
||||
title = "NoClearProgram"
|
||||
}
|
||||
program {
|
||||
backgroundColor = ColorRGBa.PINK
|
||||
extend(NoClear())
|
||||
extend {
|
||||
drawer.circle(Math.cos(seconds) * width / 2.0 + width / 2.0, Math.sin(seconds * 0.24) * height / 2.0 + height / 2.0, 20.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Usage with additional configuration
|
||||
Optionally, a static `backdrop` may be setup by providing custom code.
|
||||
|
||||
- Example 1. Customising the backdrop with an image
|
||||
```kotlin
|
||||
extend(NoClear()) {
|
||||
val img = loadImage("data\\backdrop.png")
|
||||
backdrop = {
|
||||
drawer.image(img, 0.0, 0.0, width * 1.0, height * 1.0)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- Example 2. Customising the backdrop with a checker-board pattern
|
||||
```kotlin
|
||||
extend(NoClear()) {
|
||||
backdrop = {
|
||||
val xw = width / 8.0
|
||||
val yh = height / 8.0
|
||||
drawer.fill = ColorRGBa.RED
|
||||
(0..7).forEach { row ->
|
||||
(0..7).forEach { col ->
|
||||
if ((row + col) % 2 == 0) {
|
||||
drawer.rectangle(row * xw, col * yh, xw, yh)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
# orx-no-clear
|
||||
|
||||
A simple OPENRNDR Extension that provides the classical drawing-without-clearing-the-screen functionality that
|
||||
OPENRNDR does not support natively.
|
||||
|
||||
#### Usage
|
||||
|
||||
```kotlin
|
||||
fun main() = application {
|
||||
configure {
|
||||
title = "NoClearProgram"
|
||||
}
|
||||
program {
|
||||
backgroundColor = ColorRGBa.PINK
|
||||
extend(NoClear())
|
||||
extend {
|
||||
drawer.circle(Math.cos(seconds) * width / 2.0 + width / 2.0, Math.sin(seconds * 0.24) * height / 2.0 + height / 2.0, 20.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Usage with additional configuration
|
||||
Optionally, a static `backdrop` may be setup by providing custom code.
|
||||
|
||||
- Example 1. Customising the backdrop with an image
|
||||
```kotlin
|
||||
extend(NoClear()) {
|
||||
val img = loadImage("data\\backdrop.png")
|
||||
backdrop = {
|
||||
drawer.image(img, 0.0, 0.0, width * 1.0, height * 1.0)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- Example 2. Customising the backdrop with a checker-board pattern
|
||||
```kotlin
|
||||
extend(NoClear()) {
|
||||
backdrop = {
|
||||
val xw = width / 8.0
|
||||
val yh = height / 8.0
|
||||
drawer.fill = ColorRGBa.RED
|
||||
(0..7).forEach { row ->
|
||||
(0..7).forEach { col ->
|
||||
if ((row + col) % 2 == 0) {
|
||||
drawer.rectangle(row * xw, col * yh, xw, yh)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
NB! any submitted _lambda expression_ must be valid within the `renderTarget` context.
|
||||
@@ -1,57 +1,57 @@
|
||||
package org.openrndr.extra.noclear
|
||||
|
||||
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
|
||||
import org.openrndr.math.Matrix44
|
||||
|
||||
class NoClear : Extension {
|
||||
override var enabled: Boolean = true
|
||||
private var renderTarget: RenderTarget? = null
|
||||
|
||||
/**
|
||||
* code-block to draw an optional custom backdrop
|
||||
*/
|
||||
var backdrop: (() -> Unit)? = null
|
||||
|
||||
override fun beforeDraw(drawer: Drawer, program: Program) {
|
||||
if (program.width > 0 && program.height > 0) { // only if the window is not minimised
|
||||
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)
|
||||
backdrop?.invoke() // draw custom backdrop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
renderTarget?.bind()
|
||||
}
|
||||
|
||||
override fun afterDraw(drawer: Drawer, program: Program) {
|
||||
renderTarget?.unbind()
|
||||
|
||||
renderTarget?.let {
|
||||
drawer.isolated {
|
||||
drawer.ortho()
|
||||
drawer.view = Matrix44.IDENTITY
|
||||
drawer.model = Matrix44.IDENTITY
|
||||
drawer.image(it.colorBuffer(0))
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.openrndr.extra.noclear
|
||||
|
||||
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
|
||||
import org.openrndr.math.Matrix44
|
||||
|
||||
class NoClear : Extension {
|
||||
override var enabled: Boolean = true
|
||||
private var renderTarget: RenderTarget? = null
|
||||
|
||||
/**
|
||||
* code-block to draw an optional custom backdrop
|
||||
*/
|
||||
var backdrop: (() -> Unit)? = null
|
||||
|
||||
override fun beforeDraw(drawer: Drawer, program: Program) {
|
||||
if (program.width > 0 && program.height > 0) { // only if the window is not minimised
|
||||
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)
|
||||
backdrop?.invoke() // draw custom backdrop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
renderTarget?.bind()
|
||||
}
|
||||
|
||||
override fun afterDraw(drawer: Drawer, program: Program) {
|
||||
renderTarget?.unbind()
|
||||
|
||||
renderTarget?.let {
|
||||
drawer.isolated {
|
||||
drawer.ortho()
|
||||
drawer.view = Matrix44.IDENTITY
|
||||
drawer.model = Matrix44.IDENTITY
|
||||
drawer.image(it.colorBuffer(0))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user