Multiple JME contexts in Swing?

Just wondering if it is possible to have two JME3 displays running concurrently?



Here is my startup code:



[java]

public class Main

{

public static void main(String[] args)

{

java.awt.EventQueue.invokeLater(new Runnable()

{



@Override

public void run()

{

AppSettings app1Settings = new AppSettings(true);

app1Settings.setWidth(640);

app1Settings.setHeight(480);



MyApp1 app1 = new MyApp1();

app1.setSettings(app1Settings);

app1.createCanvas();

JmeCanvasContext ctx = (JmeCanvasContext) app1.getContext();

ctx.setSystemListener(app1);

ctx.getCanvas().setPreferredSize(new Dimension(640, 480));

JFrame display1 = new MyFrame1(ctx, app1);

display1.setVisible(true);



app1.setPauseOnLostFocus(false);

app1.startCanvas();

}

});



java.awt.EventQueue.invokeLater(new Runnable()

{



@Override

public void run()

{

// generate grammar-tree view

AppSettings app2Settings = new AppSettings(true);

app2Settings.setWidth(640);

app2Settings.setHeight(480);

MyApp2 app2 = new MyApp2();

app2.setSettings(app2Settings);

app2.createCanvas();

JmeCanvasContext ctx = (JmeCanvasContext) app2.getContext();

ctx.setSystemListener(app2);

ctx.getCanvas().setPreferredSize(new Dimension(640, 480));

JFrame display2 = new MyFrame2(ctx, app2);

display2.setVisible(true);



app2.setPauseOnLostFocus(false);

app2.startCanvas();

}

});

}

}

[/java]



Seems pretty straightforward, but I get an error. If I comment either of the Runnables out, then the individual displays generate correctly. But here is the error I get if I try to do both:



[java]

Sep 19, 2011 2:20:51 PM com.jme3.app.Application handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,6,main]

java.lang.NullPointerException

at org.lwjgl.opengl.GL11.glGetError(GL11.java:1278)

at org.lwjgl.opengl.Util.checkGLError(Util.java:57)

at org.lwjgl.opengl.WindowsContextImplementation.setSwapInterval(WindowsContextImplementation.java:113)

at org.lwjgl.opengl.ContextGL.setSwapInterval(ContextGL.java:231)

at org.lwjgl.opengl.DrawableGL.setSwapInterval(DrawableGL.java:86)

at org.lwjgl.opengl.Display.setSwapInterval(Display.java:1169)

at org.lwjgl.opengl.Display.setVSyncEnabled(Display.java:1182)

at com.jme3.system.lwjgl.LwjglCanvas.createContext(LwjglCanvas.java:449)

at com.jme3.system.lwjgl.LwjglCanvas.restoreCanvas(LwjglCanvas.java:265)

at com.jme3.system.lwjgl.LwjglCanvas.runLoop(LwjglCanvas.java:194)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:223)

at java.lang.Thread.run(Thread.java:662)

Sep 19, 2011 2:20:51 PM com.jme3.renderer.lwjgl.LwjglRenderer cleanup

INFO: Deleting objects and invalidating state

[/java]



Any ideas?

No, you can use a preView and render its output to an additional swing window though, look at TestRenderToMemory

normen said:
No, you can use a preView and render its output to an additional swing window though, look at TestRenderToMemory


"No" -- meaning that it is not possible to have multiple windows?

I'll look into TestRenderToMemory.

“No” was the answer to your initial question, yeah.

Will using createPreView allow me to show two different scenes, or just a different view of one scene?

Yes you can attach any scene to the preview.

Hey,



So the TestRenderToMemory example shows a single geometry being added as “the scene”, i.e., a box geometry gets added to the viewport. But my scene is more complex than that, and I’m not sure how to “attach” it. I wish there was a more complex example than just adding a box.

You just need to attach some node, then that node works like the “normal” rootNode. :roll:

There are other examples which attach more things than a “box” …

Hmm… Ok. I’l check the source folders for those examples again then.

Well, I’m struggling to find any examples that are more helpful than what’s already in the folder jme3test/post.



Anyways, I’ve managed to attach a Skybox to my scene. But I can’t seem to add any geometry unless it is textured. Does that make sense? For instance, a box with the jme logo is displayed in the TestRenderToMemory class:



[java]

Box boxMesh = new Box(Vector3f.ZERO, 30, 30, 30);

Material material = assetManager.loadMaterial(“Interface/Logo/Logo.j3m”);

offBox = new Geometry(“box”, boxMesh);

offBox.setMaterial(material);

offBox.updateGeometricState();

offView.attachScene(offBox);

[/java]



But if I change to box to respond to lighting, nothing happens:



[java]

Box b = new Box(Vector3f.ZERO, 30, 30, 30);

offBox = new Geometry(“plane cube”, b);

Material mat = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);

mat.setBoolean(“UseMaterialColors”, true);

mat.setColor(“Ambient”, ColorRGBA.LightGray);

mat.setColor(“Diffuse”, ColorRGBA.Blue);

mat.setColor(“Specular”, ColorRGBA.LightGray);

mat.setFloat(“Shininess”, 1);

offBox.setMaterial(mat);

//offBox.setShadowMode(ShadowMode.Receive);

offBox.updateGeometricState();

offView.attachScene(offBox);

[/java]



Now, if I add the CartoonEdgeFilter, then I can see the edges of the box, but that’s it.



What am I missing?

Momoko_Fan said:
To have lighting, you need a light


Of course you do. Maybe I should have posted more code.

To have lighting, you need a light