Split Screen Example? (FIXED)

Hi, i am new to JMonkey and I am currently in the process of creating a two player boxing game. Each boxer requires for there to be a camera behind him so I am trying to create two cameras for split screen.



The current code I have has the problem of only showing one view of the camera, the second camera. When I turn off the second camera then the first one begins to work.



I have looked at 3 other forum posts here about split screen. Even though they did help me to advance I have become stuck at this one point.



Heres my current code:




        // Get the display dimensions
        DisplaySystem display = DisplaySystem.getDisplaySystem();
        int width = display.getWidth();
        int height = display.getHeight();

        /* CAMERA 1


*/
        
        // Set up the camera to match the display dimensions and set up the view frustum the camera can see
        myCamera1 = display.getRenderer().createCamera(width, height);
        myCamera1.setFrustumPerspective(45.0f, (float)width / (float)height, 1, 1000);
        
        myCamera1.setViewPortRight(0.5f);
        myCamera1.setViewPortLeft(0);
        
        // Place the camera in its position
        myCamera1.setLocation(new Vector3f(8, 5, 8));
        
        // Tell the camera what it should be looking at and which way is up
        myCamera1.lookAt(boxer1.getLocalTranslation(), new Vector3f(0, 1, 0));
        
        /* CAMERA 2
*/
        
        // Set up the camera to match the display dimensions and set up the view frustum the camera can see
        myCamera2 = display.getRenderer().createCamera(width, height);
        myCamera2.setFrustumPerspective(45.0f, (float)width / (float)height, 1, 1000);
        
        myCamera2.setViewPortRight(1);
        myCamera2.setViewPortLeft(0.5f);
        
        // Place the camera in its position
        myCamera2.setLocation(new Vector3f(-8, 5, -8));
        
        // Tell the camera what it should be looking at and which way is up
        myCamera2.lookAt(boxer2.getLocalTranslation(), new Vector3f(0, 1, 0));

        /* DISPLAY CAMERAS
*/
        
        display.getRenderer().clearBuffers();
        GameTaskQueueManager.getManager().getQueue(GameTaskQueue.RENDER).execute();
        
        myCamera1.update();
        // Display the camera view on the screen
        display.getRenderer().setCamera(myCamera1);
        
        myCamera2.update();
        // Display the camera view on the screen
        display.getRenderer().setCamera(myCamera2);
        
        display.getRenderer().flush();



I think the problem is in the last part of DISPLAY CAMERAS.

If anyone could point out my error or if someone could post an example of split screen camera I would be very grateful.

SPLIT SCREEN


You're doin' it wrong!



now, seriously:



  @Override
  public void render(float tpf) {

// flush previous content
    standardGame.getDisplay().getRenderer().renderQueue();

// set draw to left screen side
    standardGame.setCamera(..);
    standardGame.getCamera().apply();
    standardGame.getCamera().update();
// draw and flush
    standardGame.getDisplay().getRenderer().draw(rootNode);
    standardGame.getDisplay().getRenderer().renderQueue();

// set draw to right screen side
    standardGame.setCamera(..);
    standardGame.getCamera().apply();
    standardGame.getCamera().update();
// draw and flush
    standardGame.getDisplay().getRenderer().draw(rootNode);
    standardGame.getDisplay().getRenderer().renderQueue();
  } // render

Could you also post an example where you actually create some simple object, create 2 cameras that are looking at the object and start the game. Basically an entire class because im having a hard time figuring out how to get this to work.



I tried to create a new class and have it extend the StandardGame.java and then overwrite the render method with your suggestion, but now when I start the class I dont see anything nor can I quit the game normally. (Mouse stops working too)

Actually wait, I take that back I fixed it. I was overriding the render method but I also had to keep what the previous render method had in it. Also Since I was not using StandardGame but SimplePhysicsGame I had to change a few variable names. Otherwise heres the solution:


   @Override
    protected void render( float interpolation ) {

       super.render( interpolation );

        preRender();

        Renderer r = display.getRenderer();

          display.getRenderer().renderQueue();

       // set draw to left screen side
       display.getRenderer().setCamera(camera1);
       display.getRenderer().getCamera().apply();
       display.getRenderer().getCamera().update();
       // draw and flush
       display.getRenderer().draw(rootNode);
       display.getRenderer().renderQueue();

       // set draw to right screen side
       display.getRenderer().setCamera(camera2);
       display.getRenderer().getCamera().apply();
       display.getRenderer().getCamera().update();
       // draw and flush
       display.getRenderer().draw(rootNode);
       display.getRenderer().renderQueue();
       
        /** Draw the rootNode and all its children. */
        r.draw( rootNode );

        /** Call simpleRender() in any derived classes. */
        simpleRender();
       
        /** Draw the stats node to show our stat charts. */
        r.draw( statNode );

        doDebug(r);
    }