So basically its working. Nice job rickard!
Since my application is a little bit more complex and uses the Netbeans Platform i’m using the AwtPanelsContext (see TestAwtPanels for an example) for rendering to multiple Panels. It works quite well but not with the rift ;).
I added the StereoCamAppState to the TestAwtPanels (see below for a test case) but i’m getting an NPE. Maybe someone sees something? The viewport seems to be null in the FilterPostProcessor.
Heres the log:
[java]
EDT: addNotify
EDT: addNotify
EDT: componentResized 400, 300
EDT: componentResized 400, 300
OGL: Throttling update loop.
HMDInfo [HResolution = 1280, VResolution = 800, HScreenSize = 0.14976, VScreenSize = 0.0936, VScreenCenter = 0.0468, EyeToScreenDistance = 0.041, LensSeparationDistance = 0.0635, InterpupillaryDistance = 0.0647, DistortionK = [1.0, 0.22, 0.24, 0.0] , DesktopX = 0, DesktopY = 0, DisplayDeviceName = , DisplayId = 0]
Aug 13, 2013 11:25:30 AM com.jme3.app.Application handleError
Schwerwiegend: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at com.jme3.post.FilterPostProcessor.reshape(FilterPostProcessor.java:412)
at com.jme3.system.awt.AwtPanel.reshapeInThread(AwtPanel.java:270)
at com.jme3.system.awt.AwtPanel.initialize(AwtPanel.java:233)
at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:955)
at com.jme3.renderer.RenderManager.render(RenderManager.java:1029)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:252)
at com.jme3.system.awt.AwtPanelsContext.updateInThread(AwtPanelsContext.java:188)
at com.jme3.system.awt.AwtPanelsContext.access$100(AwtPanelsContext.java:44)
at com.jme3.system.awt.AwtPanelsContext$AwtPanelsListener.update(AwtPanelsContext.java:68)
at com.jme3.system.lwjgl.LwjglOffscreenBuffer.runLoop(LwjglOffscreenBuffer.java:125)
at com.jme3.system.lwjgl.LwjglOffscreenBuffer.run(LwjglOffscreenBuffer.java:151)
at java.lang.Thread.run(Thread.java:722)
EDT: removeNotify
EDT: removeNotify
AL lib: (EE) alc_cleanup: 1 device not closed
Initializing Rift…
pHMD created
Attaching sensor
[/java]
And here a Test Case:
[java]
package jrift;
import com.jme3.app.SimpleApplication;
import com.jme3.app.state.StereoCamAppState;
import com.jme3.asset.plugins.FileLocator;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;
import com.jme3.system.awt.AwtPanel;
import com.jme3.system.awt.AwtPanelsContext;
import com.jme3.system.awt.PaintMode;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class TestAwtPanels extends SimpleApplication {
private static TestAwtPanels app;
private static AwtPanel panel, panel2;
private static int panelsClosed = 0;
private boolean stereo = true;
private static void createWindowForPanel(AwtPanel panel, int location){
JFrame frame = new JFrame("Render Display " + location);
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(panel, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
if (++panelsClosed == 2){
app.stop();
}
}
});
frame.pack();
frame.setLocation(location, Toolkit.getDefaultToolkit().getScreenSize().height - 400);
frame.setVisible(true);
}
public static void main(String[] args){
Logger.getLogger("com.jme3").setLevel(Level.WARNING);
app = new TestAwtPanels();
app.setShowSettings(false);
AppSettings settings = new AppSettings(true);
settings.setCustomRenderer(AwtPanelsContext.class);
settings.setFrameRate(60);
app.setSettings(settings);
app.start();
SwingUtilities.invokeLater(new Runnable(){
public void run(){
final AwtPanelsContext ctx = (AwtPanelsContext) app.getContext();
panel = ctx.createPanel(PaintMode.Accelerated);
panel.setPreferredSize(new Dimension(400, 300));
ctx.setInputSource(panel);
panel2 = ctx.createPanel(PaintMode.Accelerated);
panel2.setPreferredSize(new Dimension(400, 300));
createWindowForPanel(panel, 300);
createWindowForPanel(panel2, 700);
}
});
}
@Override
public void simpleInitApp() {
assetManager.registerLocator("./Assets/MatDefs", FileLocator.class);
assetManager.registerLocator("./Assets/MatDefs/Post", FileLocator.class);
assetManager.registerLocator("./Assets", FileLocator.class);
assetManager.registerLocator("./Assets/Materials", FileLocator.class);
flyCam.setDragToRotate(true);
StereoCamAppState stereoCamAppState = new StereoCamAppState();
stateManager.attach(stereoCamAppState);
Box b = new Box(Vector3f.ZERO, 1, 1, 1);
Geometry geom = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
geom.setMaterial(mat);
rootNode.attachChild(geom);
panel.attachTo(true, viewPort);
guiViewPort.setClearFlags(true, true, true);
panel2.attachTo(false, guiViewPort);
}
}
[/java]