Home › Forums › Syphon › Syphon Development – Developer › Syphon JNI Binding › Reply To: Syphon JNI Binding
April 15, 2011 at 4:22 pm
#5115
Keymaster
Oh awesome. So you can send a PImage now, and the Syphon java class will handle sending that to Syphon as a texture? Very cool. I got it working in 1.2.1 using the PGraphics object to get a GL handle and manually read a texture from the screen, like so:
// OpenGL
import javax.media.opengl.*;
import processing.opengl.*;
// Syphon
import jsyphon.*;
PGraphicsOpenGL pgl;
float a;
JSyphonServer mySyphon;
void setup()
{
size(800, 600, OPENGL);
mySyphon = new JSyphonServer();
mySyphon.test();
mySyphon.initWithName("Syphon - Processing");
// get an OpenGL handle
pgl = (PGraphicsOpenGL) g;
// add shutdown and close handlers
/* Runtime.getRuntime().addShutdownHook(new Thread(new Runnable()
{
public void run()
{
ohGodStop();
}
}));
*/
}
void draw()
{
background(255);
GL gl = pgl.beginGL();
gl.glColor4f(0.7, 0.7, 0.7, 0.8);
gl.glTranslatef(width/2, height/2, 0);
gl.glRotatef(a, 1, 0, 0);
gl.glRotatef(a*2, 0, 1, 0);
gl.glRectf(-200, -200, 200, 200);
gl.glRotatef(90, 1, 0, 0);
gl.glRectf(-200, -200, 200, 200);
// copy to texture, to send to Syphon.
int[] texID = new int[1];
gl.glEnable(gl.GL_TEXTURE_RECTANGLE_EXT);
gl.glGenTextures(1, texID, 0);
gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE_EXT, texID[0]);
gl.glTexImage2D(gl.GL_TEXTURE_RECTANGLE_EXT, 0, gl.GL_RGBA8, width, height, 0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, null);
gl.glCopyTexSubImage2D(gl.GL_TEXTURE_RECTANGLE_EXT, 0,0, 0, 0, 0, width, height);
mySyphon.publishFrameTexture(texID[0], gl.GL_TEXTURE_RECTANGLE_EXT, 0, 0, width, height, width, height, false);
gl.glDeleteTextures(1, texID, 0);
pgl.endGL();
a += 0.5;
}