How I implemented a split screen?
First of all, I've created a class Camera, that has a variable that stores the position of the camera, and a variable which stores the viewport position, width and height.
The camera is created by passing a position and a viewport by the constructor. This class also has two functions, one for return the position and the other for return the viewport.
Here, I've created a list of cameras in the render class to store them. Then, in the same render class, I've created two functions, one for create a camera by receiving the position and viewport and then adding it to the list. This function is called in a base scene class function that will be shown and explained below.
The other function it's used for clear the list of cameras, because if not, when we pass to other scene, the cameras of the previous scene will be still in the list.
Here we see the function of changing the scene, which now also receives a display type, which is an enum class. This display type is copied to the variable "nextDisplay" that will be used by the next scene to create his cameras.
Finally, we see here the function that generates the cameras. Receiving the display type that I've copied before in the variable "nextDisplay", in this function we make a switch to see what display is required. I've created 4 cases:
-Normal: That case only creates one camera that has the size of the window.
-Two horizontal screens: That case creates two cameras that occupy the width of the window and half of the height.
-Two vertical screens: Opposite from the above case, here are created two cameras that occupy the height of the window and half of the width.
-Four screens: In that case, are created four cameras that each one occupy half of the width and half of the height of the window.