aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2026-08-30 22:41:25 +0530
committerAkshay Nair <phenax5@gmail.com>2026-08-30 22:41:28 +0530
commitfecebfd39809f862e098805219b15c50588bb81a (patch)
treef600ad9667ab4d087113fad0f6898d61ade97cfc
parent326474823ca31ad8ae424dd1d991c0330f2b3db4 (diff)
downloadart-playground-openrndr-fecebfd39809f862e098805219b15c50588bb81a.tar.gz
art-playground-openrndr-fecebfd39809f862e098805219b15c50588bb81a.zip
Development setup + toggling recording
-rw-r--r--.envrc1
-rw-r--r--.gitignore5
-rw-r--r--build.gradle.kts14
-rw-r--r--flake.lock27
-rw-r--r--flake.nix33
-rw-r--r--justfile8
-rw-r--r--src/main/kotlin/TemplateLiveProgram.kt22
-rw-r--r--src/main/kotlin/TemplateProgram.kt31
-rw-r--r--src/main/kotlin/org/openrndr/Preload.kt14
-rw-r--r--src/main/kotlin/phenax/extensions/HeadlessRecording.kt53
-rw-r--r--src/main/kotlin/phenax/utils/program.kt9
-rw-r--r--src/main/kotlin/play/PlayShowProgram.kt42
-rw-r--r--video/.empty1
13 files changed, 205 insertions, 55 deletions
diff --git a/.envrc b/.envrc
new file mode 100644
index 0000000..3550a30
--- /dev/null
+++ b/.envrc
@@ -0,0 +1 @@
+use flake
diff --git a/.gitignore b/.gitignore
index 07feaf6..df58f0a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,8 +5,9 @@ out
.gradle
.kotlin
.lwjgl
-video/
-screenshots/
+video/*
+!video/.empty
+screenshots/*
gui-parameters/
ffmpegOutput.txt
ShaderError.glsl
diff --git a/build.gradle.kts b/build.gradle.kts
index a154806..92868f1 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -331,6 +331,20 @@ class Openrndr {
val openrndr = Openrndr()
+tasks.register<JavaExec>("record") {
+ group = "application"
+ val runTask = tasks.named<JavaExec>("run").get()
+
+ mainClass.set(runTask.mainClass)
+ classpath = runTask.classpath
+ args = runTask.args ?: emptyList()
+
+ environment("RECORD", "1")
+ doFirst {
+ jvmArgs = (runTask.jvmArgs ?: emptyList()) + listOf("-Dorg.openrndr.application=EGL")
+ }
+}
+
if (properties["openrndr.tasks"] == "true") {
tasks.register("create executable jar for $applicationMainClass") {
group = " \uD83E\uDD8C OPENRNDR"
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..a7863d4
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,27 @@
+{
+ "nodes": {
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1787964612,
+ "narHash": "sha256-0N9nghg3nwzX6b6qc77EzjR9cu/Z+UR66FlfsCqiURs=",
+ "owner": "nixos",
+ "repo": "nixpkgs",
+ "rev": "e8be7818e19ada32105a8af937a6a473b38167ca",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nixos",
+ "ref": "nixpkgs-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "nixpkgs": "nixpkgs"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..c216c0d
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,33 @@
+{
+ inputs = {
+ nixpkgs.url = "github:nixos/nixpkgs?ref=nixpkgs-unstable";
+ };
+
+ outputs =
+ { self, nixpkgs }:
+ let
+ forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
+ in
+ {
+ devShells = forAllSystems (
+ system:
+ let
+ pkgs = import nixpkgs { inherit system; };
+ in
+ {
+ default = pkgs.mkShell rec {
+ buildInputs = with pkgs; [
+ jdk21
+ libGL
+ kotlin
+ kotlin-language-server
+ kotlin-interactive-shell
+ just
+ ];
+
+ LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs;
+ };
+ }
+ );
+ };
+}
diff --git a/justfile b/justfile
new file mode 100644
index 0000000..084ef12
--- /dev/null
+++ b/justfile
@@ -0,0 +1,8 @@
+run class:
+ ./gradlew run -Popenrndr.application={{class}}
+
+record class:
+ ./gradlew record -Popenrndr.application={{class}}
+
+update:
+ ./gradlew dependencyUpydates
diff --git a/src/main/kotlin/TemplateLiveProgram.kt b/src/main/kotlin/TemplateLiveProgram.kt
deleted file mode 100644
index 314bc54..0000000
--- a/src/main/kotlin/TemplateLiveProgram.kt
+++ /dev/null
@@ -1,22 +0,0 @@
-import org.openrndr.application
-import org.openrndr.color.ColorRGBa
-import org.openrndr.extra.olive.oliveProgram
-
-/**
- * This is a template for a live program.
- *
- * It uses oliveProgram {} instead of program {}. All code inside the
- * oliveProgram {} can be changed while the program is running.
- */
-
-fun main() = application {
- configure {
- width = 800
- height = 800
- }
- oliveProgram {
- extend {
- drawer.clear(ColorRGBa.PINK)
- }
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/TemplateProgram.kt b/src/main/kotlin/TemplateProgram.kt
deleted file mode 100644
index b8e2afe..0000000
--- a/src/main/kotlin/TemplateProgram.kt
+++ /dev/null
@@ -1,31 +0,0 @@
-import org.openrndr.application
-import org.openrndr.color.ColorRGBa
-import org.openrndr.draw.loadFont
-import org.openrndr.draw.loadImage
-import org.openrndr.extra.color.colormatrix.tint
-import kotlin.math.cos
-import kotlin.math.sin
-
-fun main() = application {
- configure {
- width = 768
- height = 576
- }
-
- program {
- val image = loadImage("data/images/pm5544.png")
- val font = loadFont("data/fonts/default.otf", 64.0)
-
- extend {
- drawer.drawStyle.colorMatrix = tint(ColorRGBa.WHITE.shade(0.2))
- drawer.image(image)
-
- drawer.fill = ColorRGBa.PINK
- drawer.circle(cos(seconds) * width / 2.0 + width / 2.0, sin(0.5 * seconds) * height / 2.0 + height / 2.0, 140.0)
-
- drawer.fontMap = font
- drawer.fill = ColorRGBa.WHITE
- drawer.text("OPENRNDR", width / 2.0, height / 2.0)
- }
- }
-}
diff --git a/src/main/kotlin/org/openrndr/Preload.kt b/src/main/kotlin/org/openrndr/Preload.kt
new file mode 100644
index 0000000..375294a
--- /dev/null
+++ b/src/main/kotlin/org/openrndr/Preload.kt
@@ -0,0 +1,14 @@
+package org.openrndr
+
+import org.openrndr.draw.*
+import phenax.extensions.HeadlessRecorder
+import phenax.utils.recordingEnabled
+
+class Preload : ApplicationPreload() {
+ override fun onProgramSetup(program: Program) {
+ println("BACKEND(${program.name}): ${program.application::class.qualifiedName}")
+ if (recordingEnabled()) {
+ program.extend(HeadlessRecorder())
+ }
+ }
+}
diff --git a/src/main/kotlin/phenax/extensions/HeadlessRecording.kt b/src/main/kotlin/phenax/extensions/HeadlessRecording.kt
new file mode 100644
index 0000000..78cde2c
--- /dev/null
+++ b/src/main/kotlin/phenax/extensions/HeadlessRecording.kt
@@ -0,0 +1,53 @@
+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
new file mode 100644
index 0000000..2d3e04b
--- /dev/null
+++ b/src/main/kotlin/phenax/utils/program.kt
@@ -0,0 +1,9 @@
+package phenax.utils
+
+fun recordDuration(durationSeconds: Int) {
+ System.setProperty("phenax.record.frameCount", (60 * durationSeconds).toString())
+}
+
+fun recordDuration(): Int? = System.getProperty("phenax.record.frameCount")?.toIntOrNull()
+
+fun recordingEnabled(): Boolean = System.getenv("RECORD") != null
diff --git a/src/main/kotlin/play/PlayShowProgram.kt b/src/main/kotlin/play/PlayShowProgram.kt
new file mode 100644
index 0000000..016378f
--- /dev/null
+++ b/src/main/kotlin/play/PlayShowProgram.kt
@@ -0,0 +1,42 @@
+package play
+
+import kotlin.math.cos
+import kotlin.math.sin
+import org.openrndr.application
+import org.openrndr.color.ColorRGBa
+import org.openrndr.draw.loadFont
+import org.openrndr.draw.loadImage
+import org.openrndr.extra.color.colormatrix.tint
+import org.openrndr.extra.olive.oliveProgram
+import phenax.utils.*
+
+fun main() = application {
+ recordDuration(10)
+
+ configure {
+ width = 640
+ height = 480
+ windowResizable = false
+ }
+
+ oliveProgram {
+ val image = loadImage("data/images/pm5544.png")
+ val font = loadFont("data/fonts/default.otf", 64.0)
+
+ extend {
+ drawer.drawStyle.colorMatrix = tint(ColorRGBa.WHITE.shade(0.2))
+ drawer.image(image)
+
+ drawer.fill = ColorRGBa.PINK
+ drawer.circle(
+ cos(seconds) * width / 2.0 + width / 2.0,
+ sin(0.5 * seconds) * height / 2.0 + height / 2.0,
+ 140.0
+ )
+
+ drawer.fontMap = font
+ drawer.fill = ColorRGBa.WHITE
+ drawer.text("OPENRNDR", width / 2.0, height / 2.0)
+ }
+ }
+}
diff --git a/video/.empty b/video/.empty
new file mode 100644
index 0000000..d72af31
--- /dev/null
+++ b/video/.empty
@@ -0,0 +1 @@
+asd