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.



[java]

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);

guiViewPort.setClearEnabled(false);

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

guiNode.setQueueBucket(Bucket.Gui);

guiNode.setCullHint(CullHint.Never);

guiViewPort.attachScene(guiNode);



// Create HUD ViewPort for right eye

Camera guiCam2 = guiCam1.clone();

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

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

guiViewPort2.setClearEnabled(false);

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

guiNode2.setQueueBucket(Bucket.Gui);

guiNode2.setCullHint(CullHint.Never);

guiViewPort2.attachScene(guiNode2);



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

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

healthBar1.setWidth(healthBarWidth);

healthBar1.setHeight(healthBarHeight);

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

guiNode.attachChild(healthBar1);



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

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

healthBar2.setWidth(healthBarWidth);

healthBar2.setHeight(healthBarHeight);

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

guiNode2.attachChild(healthBar2);



guiNode.updateGeometricState();

guiNode2.updateGeometricState();

}

[/java]



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 http://hub.jmonkeyengine.org/groups/graphics/forum/topic/shader-parameter-and-materials

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…