[orx-syphon] Move demos from test to demo, add OpenGL requirements

This commit is contained in:
Edwin Jakobs
2024-03-14 12:16:19 +01:00
parent fed97e673f
commit 82cf4e0a89
10 changed files with 102 additions and 77 deletions

View File

@@ -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))
}
}
}
}

View File

@@ -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)
}
}
}
}

View File

@@ -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)
}
}
}
}

View File

@@ -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()

View File

@@ -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

View File

@@ -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)
}
}
}

View File

@@ -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)
}
}
}