Hi everybody,
My first post here...(lot of pressure)
I am working on a little augmented reality games in java. We decided to use the power of processing to speed up coding.
We use it as an independent library in order to make it transparent for the rest of the app. The input module (from a webcam or a video) works fine thanks to GSVideo.
We would like to have a class "render" which would be able to take an array pixels[], use a PApplet, PGraphics, OPENGL etc. to draw whatever we want on it, and then return the result in a pixels[] array.
I've tried several things, from some examples found on the web...here's an example of what I want to make work :
Does someone has already used processing like this ? Every answer would be very useful !
Thanks in advance
My first post here...(lot of pressure)
I am working on a little augmented reality games in java. We decided to use the power of processing to speed up coding.
We use it as an independent library in order to make it transparent for the rest of the app. The input module (from a webcam or a video) works fine thanks to GSVideo.
We would like to have a class "render" which would be able to take an array pixels[], use a PApplet, PGraphics, OPENGL etc. to draw whatever we want on it, and then return the result in a pixels[] array.
I've tried several things, from some examples found on the web...here's an example of what I want to make work :
- package test.bibliotheques;
import java.awt.Toolkit;
import java.awt.image.MemoryImageSource;
import processing.core.PApplet;
import processing.core.PGraphics;
import processing.core.PImage;
public class testMyOpenGLInProcessing {
private PApplet applet = null;
private PGraphics context = null;
private int width;
private int height;
public testMyOpenGLInProcessing(int width, int height){
applet = new PApplet();
context = applet.createGraphics(width, height, PApplet.P3D);
applet.g = context;
this.width = width;
this.height = height;
}
public int[] augment(int[] pixels)
{
if (applet == null || context == null)
{
System.out.println("error : context null");
return null;
}
/* let's draw on it ... how can I use it as the working base ?*/
context.beginDraw();
context.background(PixelsToPImage(pixels)); // ??
context.beginShape();
context.vertex(100,100);
context.vertex(300,300);
context.endShape();
context.endDraw();
/* and then, how can I retrieve the modified image ?? */
context.loadPixels(); // ?
context.updatePixels(); // ?
return context.pixels; // ?
}
public PImage PixelsToPImage(int[] pix)
{
MemoryImageSource mis = new MemoryImageSource(width, height, pix, 0, width);
Toolkit tk = Toolkit.getDefaultToolkit();
return new PImage(tk.createImage(mis));
}
public static void main()
{
// create a GraphRenderer object
testMyOpenGLInProcessing g = new testMyOpenGLInProcessing(320, 240);
// have the GraphRenderer render out to a file; the file extension determines the output format
int[] result = g.augment(...a_pixels_array...); // ... common scenario - .
- .
- .
}
}
Does someone has already used processing like this ? Every answer would be very useful !
Thanks in advance
1