From 82cf4e0a894cd2b10f672eba4b9cda6dd870a22e Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Thu, 14 Mar 2024 12:16:19 +0100 Subject: [PATCH] [orx-syphon] Move demos from test to demo, add OpenGL requirements --- .../extra/convention/kotlin-jvm.gradle.kts | 2 +- orx-jvm/orx-syphon/README.md | 68 ++++++++++--------- .../kotlin/ClientExampleSpecificServer.kt | 0 .../src/demo/kotlin/DemoClient01.kt | 23 +++++++ .../src/demo/kotlin/DemoServer01.kt | 27 ++++++++ .../ServerExampleAlternateRenderTarget.kt | 0 .../src/main/kotlin/SyphonClient.kt | 7 ++ .../src/main/kotlin/SyphonServer.kt | 7 ++ .../src/test/kotlin/ClientExample.kt | 22 ------ .../src/test/kotlin/ServerExample.kt | 23 ------- 10 files changed, 102 insertions(+), 77 deletions(-) rename orx-jvm/orx-syphon/src/{test => demo}/kotlin/ClientExampleSpecificServer.kt (100%) create mode 100644 orx-jvm/orx-syphon/src/demo/kotlin/DemoClient01.kt create mode 100644 orx-jvm/orx-syphon/src/demo/kotlin/DemoServer01.kt rename orx-jvm/orx-syphon/src/{test => demo}/kotlin/ServerExampleAlternateRenderTarget.kt (100%) delete mode 100644 orx-jvm/orx-syphon/src/test/kotlin/ClientExample.kt delete mode 100644 orx-jvm/orx-syphon/src/test/kotlin/ServerExample.kt diff --git a/buildSrc/src/main/kotlin/org/openrndr/extra/convention/kotlin-jvm.gradle.kts b/buildSrc/src/main/kotlin/org/openrndr/extra/convention/kotlin-jvm.gradle.kts index c951d34a..30a64a88 100644 --- a/buildSrc/src/main/kotlin/org/openrndr/extra/convention/kotlin-jvm.gradle.kts +++ b/buildSrc/src/main/kotlin/org/openrndr/extra/convention/kotlin-jvm.gradle.kts @@ -35,7 +35,7 @@ val main: SourceSet by sourceSets.getting @Suppress("UNUSED_VARIABLE") val demo: SourceSet by sourceSets.creating { - val skipDemos = setOf("openrndr-demos", "orx-minim", "orx-realsense2", "orx-runway", "orx-video-profiles", "orx-midi") + val skipDemos = setOf("openrndr-demos", "orx-minim", "orx-realsense2", "orx-runway", "orx-video-profiles", "orx-midi", "orx-syphon") if (project.name !in skipDemos) { collectScreenshots(project, this@creating) { } } diff --git a/orx-jvm/orx-syphon/README.md b/orx-jvm/orx-syphon/README.md index cf82053d..b2c6be43 100644 --- a/orx-jvm/orx-syphon/README.md +++ b/orx-jvm/orx-syphon/README.md @@ -12,18 +12,21 @@ import org.openrndr.color.ColorRGBa import kotlin.math.sin -fun main() = application { - configure { - width = 1000 - height = 1000 - } +fun main() { + System.setProperty("org.openrndr.gl3.gl_type", "gl") + application { + configure { + width = 1000 + height = 1000 + } - program { - extend(SyphonServer()) + program { + extend(SyphonServer()) - extend { - drawer.background(ColorRGBa.RED) - drawer.circle(width/2.0, height/2.0, sin(seconds) * width / 2.0) + extend { + drawer.background(ColorRGBa.RED) + drawer.circle(width / 2.0, height / 2.0, sin(seconds) * width / 2.0) + } } } } @@ -38,31 +41,34 @@ import org.openrndr.draw.renderTarget import kotlin.math.* -fun main() = application { - configure { - width = 1000 - height = 1000 - } - - program { - val rt = renderTarget(100, 100) { - colorBuffer() +fun main() { + System.setProperty("org.openrndr.gl3.gl_type", "gl") + application { + configure { + width = 1000 + height = 1000 } - // You can give the server a different name - extend(SyphonServer("Test", rt)) - - extend { - /** - * This is what will be sent to Syphon, and drawn in a small corner of the screen - */ - drawer.isolatedWithTarget(rt) { - drawer.background(ColorRGBa(sin(seconds), cos(seconds / 2.0), 0.5, 1.0)) + program { + val rt = renderTarget(100, 100) { + colorBuffer() } - drawer.background(ColorRGBa.GRAY) - drawer.circle(width/2.0, height/2.0, sin(seconds) * width / 2.0) - drawer.image(rt.colorBuffer(0)) + // You can give the server a different name + extend(SyphonServer("Test", rt)) + + extend { + /** + * This is what will be sent to Syphon, and drawn in a small corner of the screen + */ + drawer.isolatedWithTarget(rt) { + drawer.background(ColorRGBa(sin(seconds), cos(seconds / 2.0), 0.5, 1.0)) + } + + drawer.background(ColorRGBa.GRAY) + drawer.circle(width / 2.0, height / 2.0, sin(seconds) * width / 2.0) + drawer.image(rt.colorBuffer(0)) + } } } } diff --git a/orx-jvm/orx-syphon/src/test/kotlin/ClientExampleSpecificServer.kt b/orx-jvm/orx-syphon/src/demo/kotlin/ClientExampleSpecificServer.kt similarity index 100% rename from orx-jvm/orx-syphon/src/test/kotlin/ClientExampleSpecificServer.kt rename to orx-jvm/orx-syphon/src/demo/kotlin/ClientExampleSpecificServer.kt diff --git a/orx-jvm/orx-syphon/src/demo/kotlin/DemoClient01.kt b/orx-jvm/orx-syphon/src/demo/kotlin/DemoClient01.kt new file mode 100644 index 00000000..cbb82294 --- /dev/null +++ b/orx-jvm/orx-syphon/src/demo/kotlin/DemoClient01.kt @@ -0,0 +1,23 @@ +import jsyphon.SyphonClient +import org.openrndr.application +import org.openrndr.color.ColorRGBa + +fun main() { + System.setProperty("org.openrndr.gl3.gl_type", "gl") + application { + configure { + width = 1000 + height = 800 + } + + program { + val syphonClient = SyphonClient() + + extend(syphonClient) + extend { + drawer.clear(ColorRGBa.BLACK) + drawer.image(syphonClient.buffer) + } + } + } +} \ No newline at end of file diff --git a/orx-jvm/orx-syphon/src/demo/kotlin/DemoServer01.kt b/orx-jvm/orx-syphon/src/demo/kotlin/DemoServer01.kt new file mode 100644 index 00000000..7dba28e4 --- /dev/null +++ b/orx-jvm/orx-syphon/src/demo/kotlin/DemoServer01.kt @@ -0,0 +1,27 @@ +import jsyphon.SyphonServer +import org.openrndr.application +import org.openrndr.color.ColorRGBa + +import kotlin.math.* + + +fun main() { + // force to use GL driver + System.setProperty("org.openrndr.gl3.gl_type", "gl") + application { + configure { + width = 1000 + height = 1000 + } + + program { + extend(SyphonServer("Test")) + + extend { + drawer.clear(ColorRGBa.PINK) + drawer.fill = ColorRGBa.WHITE + drawer.circle(drawer.bounds.center, abs(cos(seconds)) * height * 0.5) + } + } + } +} \ No newline at end of file diff --git a/orx-jvm/orx-syphon/src/test/kotlin/ServerExampleAlternateRenderTarget.kt b/orx-jvm/orx-syphon/src/demo/kotlin/ServerExampleAlternateRenderTarget.kt similarity index 100% rename from orx-jvm/orx-syphon/src/test/kotlin/ServerExampleAlternateRenderTarget.kt rename to orx-jvm/orx-syphon/src/demo/kotlin/ServerExampleAlternateRenderTarget.kt diff --git a/orx-jvm/orx-syphon/src/main/kotlin/SyphonClient.kt b/orx-jvm/orx-syphon/src/main/kotlin/SyphonClient.kt index 50556af8..23c3d777 100644 --- a/orx-jvm/orx-syphon/src/main/kotlin/SyphonClient.kt +++ b/orx-jvm/orx-syphon/src/main/kotlin/SyphonClient.kt @@ -5,10 +5,13 @@ package jsyphon import org.openrndr.Extension import org.openrndr.Program import org.openrndr.draw.* +import org.openrndr.internal.Driver import org.openrndr.internal.gl3.ColorBufferGL3 +import org.openrndr.internal.gl3.DriverTypeGL import org.openrndr.internal.gl3.TextureStorageModeGL +import org.openrndr.internal.gl3.glType class SyphonClient(private val appName: String? = null, private val serverName: String? = null): Extension { @@ -18,6 +21,10 @@ class SyphonClient(private val appName: String? = null, private val serverName: var buffer: ColorBuffer = colorBuffer(10, 10) override fun setup(program: Program) { + require(Driver.glType == DriverTypeGL.GL) { + "The SyphonClient extension will only work when using OpenGL. Use -Dorg.openrndr.gl3.gl_type=gl to force OPENRNDR to use OpenGL." + } + buffer = colorBuffer(program.width, program.height) client.init() diff --git a/orx-jvm/orx-syphon/src/main/kotlin/SyphonServer.kt b/orx-jvm/orx-syphon/src/main/kotlin/SyphonServer.kt index 5902614f..1c5cb4a6 100644 --- a/orx-jvm/orx-syphon/src/main/kotlin/SyphonServer.kt +++ b/orx-jvm/orx-syphon/src/main/kotlin/SyphonServer.kt @@ -7,8 +7,11 @@ import org.openrndr.Program import org.openrndr.draw.Drawer import org.openrndr.draw.RenderTarget import org.openrndr.draw.renderTarget +import org.openrndr.internal.Driver import org.openrndr.internal.gl3.ColorBufferGL3 +import org.openrndr.internal.gl3.DriverTypeGL +import org.openrndr.internal.gl3.glType class SyphonServer(private val name: String = "OPENRNDR", var providedTarget: RenderTarget? = null): Extension { @@ -17,6 +20,10 @@ class SyphonServer(private val name: String = "OPENRNDR", var providedTarget: Re private var targetToSend: RenderTarget? = null override fun setup(program: Program) { + require(Driver.glType == DriverTypeGL.GL) { + "The SyphonServer extension will only work when using OpenGL. Use -Dorg.openrndr.gl3.gl_type=gl to force OPENRNDR to use OpenGL." + } + server.initWithName(name) // Create a new target that binds to the main one if no target is provided diff --git a/orx-jvm/orx-syphon/src/test/kotlin/ClientExample.kt b/orx-jvm/orx-syphon/src/test/kotlin/ClientExample.kt deleted file mode 100644 index b38dfca8..00000000 --- a/orx-jvm/orx-syphon/src/test/kotlin/ClientExample.kt +++ /dev/null @@ -1,22 +0,0 @@ -import jsyphon.SyphonClient -import org.openrndr.application -import org.openrndr.color.ColorRGBa - - - -fun main() = application { - configure { - width = 1000 - height = 800 - } - - program { - val syphonClient = SyphonClient() - - extend(syphonClient) - extend { - drawer.clear(ColorRGBa.BLACK) - drawer.image(syphonClient.buffer) - } - } -} \ No newline at end of file diff --git a/orx-jvm/orx-syphon/src/test/kotlin/ServerExample.kt b/orx-jvm/orx-syphon/src/test/kotlin/ServerExample.kt deleted file mode 100644 index a21d2037..00000000 --- a/orx-jvm/orx-syphon/src/test/kotlin/ServerExample.kt +++ /dev/null @@ -1,23 +0,0 @@ -import jsyphon.SyphonServer -import org.openrndr.application -import org.openrndr.color.ColorRGBa - -import kotlin.math.* - - -fun main() = application { - configure { - width = 1000 - height = 1000 - } - - program { - extend(SyphonServer("Test")) - - extend { - drawer.clear(ColorRGBa.PINK) - drawer.fill = ColorRGBa.WHITE - drawer.circle(drawer.bounds.center, abs(cos(seconds)) * height * 0.5) - } - } -} \ No newline at end of file