I'm playing around with native code from within processing at the moment to try and get Pen Pressure readings from a Wacom tablet on OSX.
Here's where I'm up to:
native.pde
Code:
HelloWorld hw;
void setup() {
size(400, 400);
hw = new HelloWorld();
}
void draw() {
hw.displayHelloWorld();
}
new tab: HelloWorld.java
Code:
class HelloWorld {
public native void displayHelloWorld();
static {
System.loadLibrary("hello");
}
public static void main(String[] args) {
new HelloWorld().displayHelloWorld();
}
}
save sketch and then compile the helloworld class with:
javac HelloWorld.javacreate .h file with:
javah -jni HelloWorldWrite the native method implementation in file called HelloWorldImp.c, like this:
Code:
#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj) {
printf("Hello world!\n");
return;
}
and then compile using:
cc -c -I/System/Library/Frameworks/JavaVM.framework/Headers HelloWorldImp.c
followed by:
cc -dynamiclib -o libhello.jnilib HelloWorldImp.o -framework JavaVM
create a code folder and insert the jnilib into it:
libhello.jnilib
Run your sketch, and bob's your uncle: Hello World!
(based on TomC's original Alpha thread http://processing.org/discourse/yabb/YaBB.cgi?board=Tools;action=display;num=1085053494)