I’ve been trying to control the viewPort size.
I want a window size of a certain size.
but I want my viewPort size to be predefined to the same size. Independent of the window size.
I’ve tried all kinds of things to change the viewport size but nothing works. When the code runs. the viewport NO MATTER what I do is the size of the window.
How do you control the viewport size. Because resize does nothing. and I’ve tried all kinds of things with no luck.
The resize function works but inside the “simpleInitApp()” is pointless, because later in the code the viewport gets updated to a new with based on “Settings”. When and where do you change the viewport size.
I want a windows size of 1680x1050 and a viewport of 672x512. I will call setviewport to adjust the size of the draw area to keep the ratio and have black bars.
Output:
Name Default Camera[location=(53.520485, 9.194, 90.225914)
, direction=(-0.42986095, -0.11012752, -0.8961537)
res=1680x1050, parallel=false
near=1.0, far=1000.0]
public class TestMultiViews extends SimpleApplication
{
boolean resetViewPort = false;
Node root2Node;
public static void main(String[] args)
{
TestMultiViews app = new TestMultiViews();
app.start();
}
@Override
public void simpleInitApp()
{
getFlyByCamera().setMoveSpeed(100);
root2Node = new Node("Default 3d");
addLine(0);
addLine(20);
addLine(40);
addLine(60);
addLine(-20);
addLine(-40);
addLine(-60);
DirectionalLight dl = new DirectionalLight();
dl.setColor(ColorRGBA.White);
dl.setDirection(Vector3f.UNIT_XYZ.negate());
rootNode.addLight(dl);
// Setup first view
viewPort.setBackgroundColor(ColorRGBA.Black);
cam.setViewPort(0f, 1f, 0f, 1f);
cam.setLocation(new Vector3f(13.499384f, 6.2560506f, 26.529842f));
cam.setRotation(new Quaternion(1.4542222E-4f, 0.99822325f, -0.002436379f, 0.059534635f));
cam.resize(672,512,true);
// // Setup second view
// Camera cam2 = cam.clone();
// cam2.setViewPort(0f, 0.5f, 0f, 0.5f);
// cam2.resize(672,512,false);
// cam2.setLocation(new Vector3f(-0.10947256f, 1.5760219f, 4.81758f));
// cam2.setRotation(new Quaternion(0.0010108891f, 0.99857414f, -0.04928594f, 0.020481428f));
//
// ViewPort view2 = renderManager.createMainView("Bottom Left", cam2);
// view2.setClearFlags(true, true, true);
// view2.attachScene(root2Node);
rootNode.attachChild(root2Node);
//test multiview for gui
guiViewPort.getCamera().setViewPort(0f, 1f, 0f, 1f);
}
@Override
public void simpleUpdate(float tpf)
{
List<ViewPort> ports = renderManager.getMainViews();
for(ViewPort port : ports)
{
System.out.println("Name "+port.getName()+" "+port.getCamera().toString());
}
}
static int num = 0;
protected void addLine(float x)
{
Box box_b = new Box(Vector3f.ZERO, 1, 1, 1);
Geometry geom = new Geometry("Line", box_b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Diffuse", ColorRGBA.randomColor());
geom.setMaterial(mat);
geom.setLocalTranslation(x, 0, 0);
root2Node.attachChild(geom);
}
}