From 4a1a4103c38a430f4d128b57c9ee5fd22e3b6624 Mon Sep 17 00:00:00 2001 From: Rein van der Woerd Date: Tue, 25 Feb 2020 12:41:15 +0100 Subject: [PATCH] Client working! --- orx-syphon/build.gradle | 1 + orx-syphon/src/main/kotlin/SyphonClient.kt | 39 +++++++++++++++++++++ orx-syphon/src/main/kotlin/SyphonServer.kt | 2 +- orx-syphon/src/test/kotlin/ClientExample.kt | 28 +++------------ 4 files changed, 46 insertions(+), 24 deletions(-) diff --git a/orx-syphon/build.gradle b/orx-syphon/build.gradle index 86cb81c6..ba76d300 100644 --- a/orx-syphon/build.gradle +++ b/orx-syphon/build.gradle @@ -1,4 +1,5 @@ dependencies { + compile project(":orx-camera") compile "org.openrndr:openrndr-core:$openrndrVersion" compile "org.openrndr:openrndr-gl3:$openrndrVersion" compile "org.lwjgl:lwjgl-opengl:3.2.3" diff --git a/orx-syphon/src/main/kotlin/SyphonClient.kt b/orx-syphon/src/main/kotlin/SyphonClient.kt index e69de29b..4c4840da 100644 --- a/orx-syphon/src/main/kotlin/SyphonClient.kt +++ b/orx-syphon/src/main/kotlin/SyphonClient.kt @@ -0,0 +1,39 @@ +import jsyphon.JSyphonClient +import jsyphon.JSyphonServer +import org.lwjgl.opengl.GL33C +import org.openrndr.Extension +import org.openrndr.Program +import org.openrndr.draw.* +import org.openrndr.internal.gl3.ColorBufferGL3 + + +class SyphonClient: Extension { + override var enabled = true + + private val client = JSyphonClient() + var buffer: ColorBuffer = colorBuffer(10, 10) + + override fun setup(program: Program) { + var buffer = colorBuffer(program.width, program.height) + client.init() + } + + override fun beforeDraw(drawer: Drawer, program: Program) { + if (client.hasNewFrame()) { + val img = client.newFrameImageForContext() + val w = img.textureWidth() + val h = img.textureHeight() + + val rectBuffer = ColorBufferGL3(GL33C.GL_TEXTURE_RECTANGLE, img.textureName(), w, h, + 1.0, ColorFormat.RGBa, ColorType.UINT8, 0, BufferMultisample.Disabled, Session.root) + + if (buffer.height != h || buffer.width != w) { + buffer = colorBuffer(w, h) + } + + rectBuffer.copyTo(buffer) + } + } +} + + diff --git a/orx-syphon/src/main/kotlin/SyphonServer.kt b/orx-syphon/src/main/kotlin/SyphonServer.kt index aea2e475..04d5f9b5 100644 --- a/orx-syphon/src/main/kotlin/SyphonServer.kt +++ b/orx-syphon/src/main/kotlin/SyphonServer.kt @@ -32,7 +32,7 @@ class SyphonServer(private val name: String = "OPENRNDR", var target: RenderTarg drawer.image(target?.colorBuffer(0)!!) val glBuffer = target?.colorBuffer(0) as ColorBufferGL3 - println(glBuffer.multisample) + println(glBuffer.target) // Send to Syphon server.publishFrameTexture( diff --git a/orx-syphon/src/test/kotlin/ClientExample.kt b/orx-syphon/src/test/kotlin/ClientExample.kt index cb13ddea..d11f98b6 100644 --- a/orx-syphon/src/test/kotlin/ClientExample.kt +++ b/orx-syphon/src/test/kotlin/ClientExample.kt @@ -1,38 +1,20 @@ -import jsyphon.JSyphonClient -import jsyphon.JSyphonImage -import org.lwjgl.opengl.GL11C.GL_TEXTURE_2D import org.openrndr.application import org.openrndr.color.ColorRGBa -import org.openrndr.draw.* -import org.openrndr.internal.Driver -import org.openrndr.internal.gl3.ColorBufferGL3 -import kotlin.math.sin fun main() = application { configure { width = 1000 - height = 1000 + height = 800 } program { - val client = JSyphonClient() - client.init() - + val syphonClient = SyphonClient() + extend(syphonClient) extend { - drawer.background(ColorRGBa.RED) - - if (client.hasNewFrame()) { - println("hasnewframe") - val img = client.newFrameImageForContext() - val buffer = ColorBufferGL3(GL_TEXTURE_2D, img.textureName(), img.textureWidth(), img.textureHeight(), - 1.0, ColorFormat.RGBa, ColorType.UINT8, 1, BufferMultisample.Disabled, Session.active) - - - drawer.image(buffer) - } - + drawer.background(ColorRGBa.BLACK) + drawer.image(syphonClient.buffer) } } } \ No newline at end of file