My solution for Processing 2.0.1 + Syphon
in
Share your Work
•
3 months ago
Hi All
Processing output like a Syphon server.
jsyphon used from
syphon-implementations by
andres
works well with any Processing's Demo/Graphics sketches.
If someone wants to wrap this solution to the library - I agree.
-
import javax.media.opengl.GL2;import jsyphon.*;
class SyphonServer2{protected JSyphonServer syphon;protected GL2 gl;protected int[] texID;protected int[] syphonFBO;public SyphonServer2(String name){syphon = new JSyphonServer();syphon.initWithName(name);println("Starting the syphon server:"+name);try {gl = ((PGraphicsOpenGL)g).pgl.gl.getGL2();} catch (javax.media.opengl.GLException e) {println("OpenGL 2 not supported!");}texID = new int[1];gl.glGenTextures(1, texID, 0);gl.glBindTexture(GL2.GL_TEXTURE_RECTANGLE, texID[0]);gl.glTexImage2D(GL2.GL_TEXTURE_RECTANGLE, 0, GL2.GL_RGBA8, width, height, 0, GL2.GL_RGBA, GL2.GL_UNSIGNED_BYTE, null);int[] defaultFBO = new int[1];gl.glGetIntegerv(GL2.GL_FRAMEBUFFER_BINDING, defaultFBO, 0);syphonFBO = new int[1];gl.glGenFramebuffers(1, syphonFBO, 0);gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, syphonFBO[0]);gl.glFramebufferTexture2D(GL2.GL_FRAMEBUFFER, GL2.GL_COLOR_ATTACHMENT0, GL2.GL_TEXTURE_RECTANGLE, texID[0], 0);gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, defaultFBO[0]);}public void send(){int[] defaultFBO = new int[1];gl.glGetIntegerv(GL2.GL_FRAMEBUFFER_BINDING, defaultFBO, 0);//println("fbo="+defaultFBO[0]);gl.glBindFramebuffer(GL2.GL_READ_FRAMEBUFFER, defaultFBO[0]);gl.glBindFramebuffer(GL2.GL_DRAW_FRAMEBUFFER, syphonFBO[0]);gl.glBlitFramebuffer(0, 0, width, height,0, 0, width, height,GL2.GL_COLOR_BUFFER_BIT, GL2.GL_LINEAR);syphon.publishFrameTexture(texID[0], GL2.GL_TEXTURE_RECTANGLE, 0, 0, width, height, width, height, false);gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, defaultFBO[0]);}public void stop(){println("deleting textures");gl.glDeleteTextures(1, texID, 0);gl.glDeleteFramebuffers(1, syphonFBO, 0);if(syphon!=null) {println("stopping the syphon server");syphon.stop();}}}SyphonServer2 syphon;
...
void setup() {...syphon = new SyphonServer2("Test server");}
void draw() {...
syphon.send();}
void dispose() {syphon.stop();}
1