Running multiple instances of jME in multiple JFrames possible?

Hey community :wink:



I have a (hopefully) short question: Is it possible to instantiate more than one instance of jME in the same JVM so that I can let it draw into different JFrames? I tried to start two instances out of Threads, but either both instances do not respond or I get an LWJGL exception. Can it be that these two Threads share one OpenGL context?



My approach is to create one Swing-based application, where the user can start multiple instances of jME that render in their own JFrame or Panel. I looked at the tests, that come bundled with jME3. These tests only use multiple Canvases on the same instance, what differs from my intent.



Is it possible what I try to achieve? How? Thanks so much :slight_smile:

1 Like

Probably not.

If you need multiple views, use viewports in jme.

Oh, quick answer, tack!

If I get it right, viewports have the effect of having multiple cameras in the same scene, right? So it is not possible to watch different scenes through these viewports?



Edit: Just found this: http://hub.jmonkeyengine.org/groups/general-2/forum/topic/what-exactly-is-viewport/

Looks like this is not the solution :S

Each viewport can have a different camera, and can look at a different scene if you wish. Viewports can also be overlaid on top of each other, for instance to get the floating gun effect in an FPS.

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:multiple_camera_views

Ok, I see :slight_smile:

So what I meant with “scene” basically is an independent running game, preferably running in a frame or panel. I came up with solutions like this, but it won’t work:



[java]

public class Foo extends SimpleApplication {



public static void main(String[] args) {

Thread t1, t2;



t1 = new Thread(new Runnable() {

public void run() {

Foo app = new Foo();

app.start(); // start the game

}

});

t1.start();





t2 = new Thread(new Runnable() {

public void run() {

Foo app = new Foo();

app.start(); // start the game #2

}

});

t2.start();

}



@Override

public void simpleInitApp() {

Box b = new Box(Vector3f.ZERO, 1, 1, 1); // create cube shape at the origin

Geometry geom = new Geometry(“Box”, b); // create cube geometry from the shape

Material mat = new Material(assetManager,

“Common/MatDefs/Misc/Unshaded.j3md”); // create a simple material

mat.setColor(“Color”, ColorRGBA.Blue); // set color of material to blue

geom.setMaterial(mat); // set the cube’s material

rootNode.attachChild(geom); // make the cube appear in the scene

}

}

[/java]

You do not want to launch multiple instances of jme and sync them.

You don’t want threads to do that either. Just have the one scene, have two nodes that are children of root node, and set each of your two viewports to view each of the nodes.

Then you can supply two appStates where each one controls one of the nodes. That way you get separate update loops etc.

It is also easy to spawn more “views” that way, and no threading headache.



You only need threading really for slow calculations or IO.

Oh that sounds like a potential solution :slight_smile:

But is it possible to do total different things in these scenes? E.g. I have a textured background on scene #1 and only a black filled on scene #2? What is an appState and how do I supply it? Is it possible to pause these scenes then when I have separate update loops? It is perfectly ok if these games would run asynchronously, I do not want to synchronize them :slight_smile:

yes to all questions

It is all described in the documentation https://wiki.jmonkeyengine.org/legacy/doku.php/jme3#tutorials_for_beginners

1 Like

Ah ok, thanks a lot!

I will have a look into it and come back, if any problems :wink: