aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2026-10-03 22:37:16 +0530
committerAkshay Nair <phenax5@gmail.com>2026-10-03 22:44:48 +0530
commitb32d32248e0bfd6e763991b14c9d7bf29063ed29 (patch)
treece607e60d9ffa267e42bca69b80db800ff67d210 /src/main
parent592603fdeedfd4e6784606b9e7c9c8fdb306af42 (diff)
downloadart-playground-openrndr-b32d32248e0bfd6e763991b14c9d7bf29063ed29.tar.gz
art-playground-openrndr-b32d32248e0bfd6e763991b14c9d7bf29063ed29.zip
Fix recording
Diffstat (limited to 'src/main')
-rw-r--r--src/main/kotlin/cloak/CloakProgram.kt2
-rw-r--r--src/main/kotlin/newton/NewtonProgram.kt2
-rw-r--r--src/main/kotlin/org/openrndr/Preload.kt14
-rw-r--r--src/main/kotlin/phenax/extensions/CameraManager.kt4
-rw-r--r--src/main/kotlin/phenax/extensions/HeadlessRecording.kt53
-rw-r--r--src/main/kotlin/phenax/utils/program.kt17
-rw-r--r--src/main/kotlin/seigaiha/SeigaihaProgram.kt2
-rw-r--r--src/main/kotlin/vacation/VacationProgram.kt4
-rw-r--r--src/main/kotlin/vista_night/VistaNightProgram.kt2
-rw-r--r--src/main/kotlin/warping/WarpingProgram.kt2
10 files changed, 27 insertions, 75 deletions
diff --git a/src/main/kotlin/cloak/CloakProgram.kt b/src/main/kotlin/cloak/CloakProgram.kt
index 9f96e29..2c125ea 100644
--- a/src/main/kotlin/cloak/CloakProgram.kt
+++ b/src/main/kotlin/cloak/CloakProgram.kt
@@ -8,7 +8,7 @@ import phenax.utils.*
fun main() = application {
recordDuration(5.seconds())
- if (recordingEnabled || screenshotEnabled) {
+ if (captureEnabled) {
configure {
width = 1920
height = 1440
diff --git a/src/main/kotlin/newton/NewtonProgram.kt b/src/main/kotlin/newton/NewtonProgram.kt
index cb59c4d..0913b99 100644
--- a/src/main/kotlin/newton/NewtonProgram.kt
+++ b/src/main/kotlin/newton/NewtonProgram.kt
@@ -10,7 +10,7 @@ import phenax.utils.*
fun main() = application {
recordDuration(37.seconds())
- if (recordingEnabled || screenshotEnabled) {
+ if (captureEnabled) {
configure {
width = 1920
height = 1080
diff --git a/src/main/kotlin/org/openrndr/Preload.kt b/src/main/kotlin/org/openrndr/Preload.kt
index 9664416..e6a9688 100644
--- a/src/main/kotlin/org/openrndr/Preload.kt
+++ b/src/main/kotlin/org/openrndr/Preload.kt
@@ -1,17 +1,23 @@
package org.openrndr
import org.openrndr.draw.*
-import org.openrndr.extensions.Screenshots
import org.openrndr.extra.olive.*
-import phenax.extensions.HeadlessRecorder
+import org.openrndr.ffmpeg.ScreenRecorder
import phenax.extensions.HeadlessScreenshot
import phenax.utils.*
class Preload : ApplicationPreload() {
override fun onProgramSetup(program: Program) {
- println("BACKEND(${program.name}): ${program.application::class.qualifiedName}")
+ println("Program: ${program.name}")
if (recordingEnabled) {
- program.extend(HeadlessRecorder())
+ program.extend(ScreenRecorder()) {
+ outputToVideo = true
+ outputFile = "video/${program.name}.mp4"
+ frameRate = 60
+ maximumDuration = recordDuration()
+ quitAfterMaximum = true
+ multisample = BufferMultisample.SampleCount(16)
+ }
} else if (screenshotEnabled) {
program.extend(HeadlessScreenshot())
}
diff --git a/src/main/kotlin/phenax/extensions/CameraManager.kt b/src/main/kotlin/phenax/extensions/CameraManager.kt
index 5112332..1f03493 100644
--- a/src/main/kotlin/phenax/extensions/CameraManager.kt
+++ b/src/main/kotlin/phenax/extensions/CameraManager.kt
@@ -35,7 +35,7 @@ class CameraManager(public var cameraPosition: Vector3, public var cameraRotatio
}
override fun setup(program: Program) {
- if (recordingEnabled || screenshotEnabled) return
+ if (captureEnabled) return
cameraQuaternion = Quaternion.fromAngles(cameraRotation.x, cameraRotation.y, cameraRotation.z)
@@ -99,7 +99,7 @@ class CameraManager(public var cameraPosition: Vector3, public var cameraRotatio
override fun beforeDraw(drawer: Drawer, program: Program) {}
override fun afterDraw(drawer: Drawer, program: Program) {
- if (recordingEnabled || screenshotEnabled) return
+ if (captureEnabled) return
drawer.fontMap = font
drawer.fill = ColorRGBa.WHITE
diff --git a/src/main/kotlin/phenax/extensions/HeadlessRecording.kt b/src/main/kotlin/phenax/extensions/HeadlessRecording.kt
deleted file mode 100644
index 78cde2c..0000000
--- a/src/main/kotlin/phenax/extensions/HeadlessRecording.kt
+++ /dev/null
@@ -1,53 +0,0 @@
-package phenax.extensions
-
-import org.openrndr.*
-import org.openrndr.draw.*
-import org.openrndr.ffmpeg.VideoWriter
-import phenax.utils.recordDuration
-
-class HeadlessRecorder : Extension {
- override var enabled: Boolean = true
-
- var videoTarget: RenderTarget? = null
- var videoWriter: VideoWriter? = null
- var maxFrameCount: Int? = null
-
- override fun setup(program: Program) {
- val width = program.application.configuration.width
- val height = program.application.configuration.height
- program.width = width
- program.height = height
- videoWriter =
- VideoWriter().apply {
- frameRate = 60
- size(width, height)
- output("video/${program.name}.mp4")
- start()
- }
- videoTarget =
- renderTarget(width, height) {
- colorBuffer()
- depthBuffer()
- }
- maxFrameCount = recordDuration()
- program.clock = { program.frameCount / (videoWriter?.frameRate?.toDouble() ?: 0.0) }
- }
-
- override fun beforeDraw(drawer: Drawer, program: Program) {
- videoTarget?.bind()
- program.backgroundColor?.let { drawer.clear(it) }
- }
-
- override fun afterDraw(drawer: Drawer, program: Program) {
- val target = videoTarget ?: return
- val writer = videoWriter ?: return
-
- target.unbind()
- writer.frame(target.colorBuffer(0))
-
- if (program.frameCount >= (maxFrameCount ?: 60 * 10)) {
- writer.stop()
- program.application.exit()
- }
- }
-}
diff --git a/src/main/kotlin/phenax/utils/program.kt b/src/main/kotlin/phenax/utils/program.kt
index cfbe9c9..fdb6197 100644
--- a/src/main/kotlin/phenax/utils/program.kt
+++ b/src/main/kotlin/phenax/utils/program.kt
@@ -4,23 +4,22 @@ import java.io.File
import kotlin.properties.ReadOnlyProperty
import org.openrndr.ApplicationBuilder
import org.openrndr.Program
-import org.openrndr.draw.*
import org.openrndr.color.*
+import org.openrndr.draw.*
import org.openrndr.extra.filewatcher.watchingFile
import org.openrndr.extra.olive.oliveProgram as oliveProgramOriginal
-fun Int.seconds(): Int = this * 1000
-
-fun Int.minutes(): Int = this.seconds() * 60
+fun Number.seconds(): Number = this
-fun recordDuration(millis: Int) {
- System.setProperty("phenax.record.frameCount", (60 * millis / 1000).toInt().toString())
+fun recordDuration(millis: Number) {
+ System.setProperty("phenax.record.recordDuration", millis.toDouble().toString())
}
-fun recordDuration(): Int? = System.getProperty("phenax.record.frameCount")?.toIntOrNull()
+fun recordDuration(): Double = System.getProperty("phenax.record.recordDuration")?.toDoubleOrNull() ?: 5000.0
val recordingEnabled: Boolean by lazy { System.getenv("PHENAX_RECORD") != null }
val screenshotEnabled: Boolean by lazy { System.getenv("PHENAX_SCREENSHOT") != null }
+val captureEnabled: Boolean by lazy { recordingEnabled || screenshotEnabled }
// fun classDir(): String =
// "src/main/kotlin/${stackRootClassName(sanitize =
@@ -31,7 +30,7 @@ val screenshotEnabled: Boolean by lazy { System.getenv("PHENAX_SCREENSHOT") != n
// Have to keep the same name (oliveProgram) to get update on save to work
fun ApplicationBuilder.oliveProgram(init: Program.() -> Unit) {
- if (recordingEnabled || screenshotEnabled) {
+ if (captureEnabled) {
program(init)
} else {
// TODO: Make watching shader files work
@@ -89,7 +88,7 @@ fun Program.liveComputeShader(name: String): ReadOnlyProperty<Any?, ComputeShade
var cs: ComputeShader = ComputeShader.fromCode(shaderCode, name)
- if (!recordingEnabled || screenshotEnabled) {
+ if (!captureEnabled) {
var lastCompiledCode: String = shaderCode
program.extend {
diff --git a/src/main/kotlin/seigaiha/SeigaihaProgram.kt b/src/main/kotlin/seigaiha/SeigaihaProgram.kt
index ae3e411..09993d2 100644
--- a/src/main/kotlin/seigaiha/SeigaihaProgram.kt
+++ b/src/main/kotlin/seigaiha/SeigaihaProgram.kt
@@ -10,7 +10,7 @@ import phenax.utils.*
fun main() = application {
recordDuration(5.seconds())
- if (recordingEnabled || screenshotEnabled) {
+ if (captureEnabled) {
configure {
width = 1920
height = 1080
diff --git a/src/main/kotlin/vacation/VacationProgram.kt b/src/main/kotlin/vacation/VacationProgram.kt
index 0ed8c70..b95af0f 100644
--- a/src/main/kotlin/vacation/VacationProgram.kt
+++ b/src/main/kotlin/vacation/VacationProgram.kt
@@ -10,7 +10,7 @@ import phenax.utils.*
fun main() = application {
recordDuration(5.seconds())
- if (recordingEnabled || screenshotEnabled) {
+ if (captureEnabled) {
configure {
width = 1920
height = 1080
@@ -43,7 +43,7 @@ fun main() = application {
cs.image("noise_texture", 1, noiseBuffer.imageBinding(0, ImageAccess.READ))
cs.uniform("seconds", seconds)
- cs.uniform("enable_antialiasing", antialiasingEnabled || recordingEnabled || screenshotEnabled)
+ cs.uniform("enable_antialiasing", antialiasingEnabled || captureEnabled)
cs.image("output_image", 0, outputBuffer.imageBinding(0, ImageAccess.WRITE))
cs.execute(outputBuffer.width, outputBuffer.height, 1)
drawer.image(outputBuffer)
diff --git a/src/main/kotlin/vista_night/VistaNightProgram.kt b/src/main/kotlin/vista_night/VistaNightProgram.kt
index dcd97b4..9eeb11e 100644
--- a/src/main/kotlin/vista_night/VistaNightProgram.kt
+++ b/src/main/kotlin/vista_night/VistaNightProgram.kt
@@ -10,7 +10,7 @@ import phenax.utils.*
fun main() = application {
recordDuration(5.seconds())
- if (recordingEnabled || screenshotEnabled) {
+ if (captureEnabled) {
configure {
width = 1920
height = 1080
diff --git a/src/main/kotlin/warping/WarpingProgram.kt b/src/main/kotlin/warping/WarpingProgram.kt
index f1cb991..706935b 100644
--- a/src/main/kotlin/warping/WarpingProgram.kt
+++ b/src/main/kotlin/warping/WarpingProgram.kt
@@ -10,7 +10,7 @@ import phenax.utils.*
fun main() = application {
recordDuration(5.seconds())
- if (recordingEnabled || screenshotEnabled) {
+ if (captureEnabled) {
configure {
width = 1920
height = 1080