I’m attempting to write an application that will stream a single incoming video feed to both eyes using an Oculus Rift DK2. In Linux, I’ve configured the Rift as a second monitor. Thanks to another topic on here, I’m able to create a second window, full screen, in Rift’s viewport.. I would like to have a control window on my monitor, for setting various options, and showing a headset feed preview.
I’ve got some issues however. I’m intending on rendering a 3D scene, incorporating a video feed. I’d like to render this scene once, and display it to both eyes. I figured the best way to go about that was to render to a single PGraphics framebuffer, then draw it twice, once for each eye. For the sake of showing what the user is seeing in the control window, I’d like to pass the PGraphics object from one applet to another, or a rendered PImage from it. However, while I’m able to reference simple variables in the child from the parent, or vice-versa, I don’t seem to be able to pass either of these visual data types and have them render. I either don’t get a rendered image, without an error, or I’ll get an error stating that I’m drawing outside of when OpenGL would prefer I do so.
Is there some sort of data escrow account I could use to asynchronously pass images from one applet to another? Is there some simpler or more correct way of accomplishing what I’m trying to do? I’d like to get GStreamer coming into this application, and inserting the video feed into the 3D scene, and if I can’t get images between applications, I worry that I won’t be able to access the GStream images from both applets, if one is binding to a port. It’s because of this that I’d really prefer to have this data be “owned” by either parent or child, and then passed out to the other. Because it’s just a heads up of what the operator is seeing, I’m not the most concerned if the monitor’s version is of a similar frame rate, or even if it’s lagging slightly.
Furthermore, if I render the scene in the child applet, I’m forced to declare the applet rendered with P2D or P3D, which results in a ThreadDeath error upon closing the application. If I render the scene in the parent applet, I don’t face this error.
It’s currently using the same buffer for each eye, but I might add a true stereo effect later. In that case, I’d really like to avoid rendering everything a third time!
Rift rift;
PImage i;
void settings() {
size(480, 515, P2D);
}
void setup()
{
rift = new Rift(this);
String[] args = {"Rift"};
PApplet.runSketch(args, rift);
fill(255,0,255);
rectMode(CENTER);
}
void draw() {
background(0);
rect(mouseX, mouseY, 25, 25);
// I would like to call this here
// image(rift.buffer,0,0,200,200);
}
public class Rift extends PApplet {
riftStreamer parent;
PGraphics buffer;
Rift(riftStreamer myParent) {
parent = myParent;
}
void settings() {
fullScreen(P2D, 2);
}
void setup()
{
buffer = createGraphics(1030, 960, P3D);
println(width, height);
buffer.rectMode(CENTER);
}
void draw() {
background(50, 50, 50);
// Drawing to a buffer to be reused
buffer.beginDraw();
buffer.background(0);
buffer.rect(parent.mouseY*2, width-parent.mouseX*2, 50, 50);
buffer.endDraw();
// Draw once for each eye
image(buffer, 0, 0);
image(buffer, 0, height/2);
}
}