Multiple GUI ViewPorts

Hi, I am currently trying to get two GUI ViewPorts that are displayed side by side, both half the width of the window.

I am using [java]camera2.setViewPort(1, 2, 0, 1);[/java] to display the second game camera on the right half of the screen which is working perfectly but when I try to do the same thing with the HUD, it only displays the left one.

I tried using one ViewPort but the problem then is that when a image is positioned at the very right of the left half of the screen (it will be displayed on two screens later) the image, of course, overlaps to the other half, when it should actually be cut off.

My code for the two gui viewports looks like this.


private void initHUD() {

// Create HUD ViewPort for left eye

Camera guiCam1 = new Camera(rm.getPostView(“Gui Default”).getCamera().getWidth()/2, cameraHeight);

ViewPort guiViewPort = rm.createPostView(“HUD ViewPort Left”, guiCam1);


guiNode = new Node(“HUD Node Left”);




// Create HUD ViewPort for right eye

Camera guiCam2 = guiCam1.clone();

guiCam2.setViewPort(1, 2, 0, 1);

ViewPort guiViewPort2= rm.createPostView(“HUD ViewPort Right”, guiCam2);


guiNode2 = new Node(“HUD Node Right”);




Picture healthBar1 = new Picture(“healthBar Left Eye”);

healthBar1.setImage(Utils.getAssetManager(), “data/healthBar.png”, true);



healthBar1.setPosition(5, guiCam1.getHeight() - 5 - healthBarHeight);


Picture healthBar2 = new Picture(“healthBar Right Eye”);

healthBar2.setImage(Utils.getAssetManager(), “data/healthBar.png”, true);



healthBar2.setPosition(5, guiCam2.getHeight() - 5 - healthBarHeight);






As I wrote above, the left one works properly, the right one won’t show.

Any hints would be highly appreciated.

Thanks in advance, Phil

Hi, i think the line “guiCam2.setViewPort(1,2,0,1)” is the issue. Try to set it to (0,1,0,1) to see if it is displayed. I think 1 is the ratio of fullscreen(1*resolution), so the right view should be (0.5,1,0,1) or something like that. Another way to find out whats going wrong is to get the viewport dimensions of the default cam.

Hi Lutherion,

I just tried it out and both ways it does show, however it shows on the left side, not on the right.

As I understand it, the left and right ratio is ratioviewportWidth that’s why I set it to 1, 2 for the main view. 1viewportWidth being the center of the window, 2*viewportWidth being the very right of the window. There it works, that’s why I am so confused.

Thanks though.

Yeah, i think the left should be (0,0.5,0,1) and the right (0.5,1,0,1). Pleasure to me to help others if i have the time. So try one viewport seperatly with a ratio between 0 and 1.

Another hint i could give is to load the gui-lib i’m currently developing where viewports are implemented and to look how it’s implemented. The class is ViewportLayer.

Link is contained in the post

Hi, thanks for that hint.

Sadly, still no luck though.

Tried setting it to (0, 0.5, 0, 1) and (0.5, 1, 0, 1) but the only effect is that the left viewport is only a quarter of the screen in width. Makes sense actually since setting it to 0, 0.5 makes it half as wide as the cam which in turn is half the width of the screen.

I am starting to think this could be a bug in jME, somewhere in the gui stuff since the very same settings (0,1) (1,2) work perfectly with Main Viewports…