We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Processing, JNI and OpenGL...
Page Index Toggle Pages: 1
Processing, JNI and OpenGL... (Read 703 times)
Processing, JNI and OpenGL...
Feb 25th, 2010, 9:56pm
 
Hello

I am curious about the feasibility of integrating Processing into a C / Obj-C environment using JNI.

I have read over Apples JNI documents:

http://developer.apple.com/java/jniuniversal.html & http://developer.apple.com/mac/library/technotes/tn2005/tn2147.html#TNTAG1

and am curious if it is possible to to shim in an arbitrary OpenGL context into JAWT or whatever is actually responsible for drawing. My goal is to integrate Processing's drawing with either my pre-existing GL world, or at the least have it render to a texture to output an image of the Processing GL world.

I have done something similar with OpenFrameworks (wrapping OF apps to Quartz Composer plugins), and was able to simply set the OpenGLContext (CGLSetCurrentContext() on Mac OS X). This was slightly easier as OF always draws to GL, is C, and shimming my own context in was fairly straightforward due to abstractions in OF for native windowing.

However I am new to lower level JNI coding and an unfamiliar with more complex Java GUi drawing. I expect difficulties/complications to get to to raw rendering context that Processing actually uses, and since PApplets can use multiple renderers, the complication seems to grow...

Has anyone ever attempted anything like this (Processing drawing within other environments)? I am curious if anyone has any pointers, or examples/advice.

My rough idea is to implement a custom PApplet class that handles the call to setup, draw etc similar , force noLoop and to manually call redraw() whenever my app draws (to synchronize), however, I'm at a loss as how the actual drawing framework happens in Processing. My limited understanding is that this uses AWT behind the scenes, and that in doing some research, it seems one can get at the AWT canvas http://lists.apple.com/archives/java-dev/2006/Apr/msg00317.html , but its unclear to me if I can 'capture' that, and how that scenario changes if P3D, OPENGL, or P2D is chosen.

Some possible choices are to either limit to software drawing P3D and just get a buffer of bytes and upload as a texture, or force OPENGL and shim in a pre-existing context to Processings gl command stream. Thoughts?

In short, anyone have any advice? Im curious as to how feasible this may be.

Thanks in advance!
Page Index Toggle Pages: 1