javalibgdxviewportscene2dviewport3d

libgdx how to split the screen to 4 parts


This is how I want my screen to look like: main screen In the left up corner I need to have 6 3d models So I will do that using the PerspectiveCamera. the right up corner jest need to present some data so I will do that using the scene2d. The bottom left corner need a combination when the 3d models will be drown with a batch.dra() and the PerspectiveCamera and the data about the models will be a scene2d. In the right bottom I jest need a scene2d table to show all the connected users. My question is how do I split my screen to 4 so every part of the screen will be rendered differently.


Solution

  • You can try offsetting the viewport with setScreenX, setScreenY and screenBounds. You do need to use 2 viewports now.

    Otherwise it is possible to alter the viewport directly. Gdx.gl.glViewport( 0,Gdx.graphics.getHeight() / 2,Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight() / 2 ); should draw everything in the upper corner. In update it will look like this:

    `Gdx.gl.glViewport( 0,Gdx.graphics.getHeight() / 2,Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight() / 2 );
    //Draw upper right window stuff
    
    Gdx.gl.glViewport( 0,0, Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
    //Draw your stage and just leave the upper right window/table cell transparent
    

    I didn't test out either solution so I'm not sure if it will work for you.