ViewPort Size

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.

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

    public void simpleInitApp()
        root2Node = new Node("Default 3d");

        DirectionalLight dl = new DirectionalLight();


        // Setup first view
        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));

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

        //test multiview for gui 
        guiViewPort.getCamera().setViewPort(0f, 1f, 0f, 1f);

    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.setLocalTranslation(x, 0, 0);

FYI: How to type code blocks


1 Like

I don’t know the answer to your question as it’s lower level than I usually dig and I’ve never needed such a thing (or imagined needing it)…

…but to forestall the half-dozen incorrect replies you are about to get:

You actually want the pixelated look of stretching a low res frame buffer to a bigger window size. Correct?


I was thinking of switching to JME from my personal enginge and define viewPort to a certain size and pixelate to larger windows. It is an 8bit style game.

And to forestall the new replies to that…

For awareness, there are other ways to achieve what you want that you are likely about to hear about.

For example: rendering to an off screen framebuffer and then using that as the texture for a full screen quad. It’s not really going to be any slower than what you are originally triyng to do. (This has the added benefit of being able to apply a composite video shader so that it looks like the original 8-bit games from ‘back in the day’ and not the modern block things we see a lot of now.)

Anyway, not a direct answer to your question but worth mentioning just so that maybe it doesn’t get mentioned five more times.

Yes, I’ve thought of that. In my game, I render to a frame buffer only. I render 2 textures (2 viewports), a GUI and a 3d view port.
One viewport is Ortho and other is 3D. and each have the ability to have post filter processing added to it. The 3d view port has 3 post processing filters.

Then I take the 2 final outputs and then render to another frame buffer with a simple combine filter.
Then I take the 1 output and then render that to a frame buffer for a CRT effect, (scanline, black/white and etc…)
Then I take that output and render it to the screen.

I could do that. Create a viewport with the size I want and render it to a frame buffer and then take that texture and render to the screen.

Never thought of that.

1 Like

Ah, yeah, sounds like you are almost there already anyway. Cool.