Introduction

There are a lot of examples of split screen in video games. The most common use is when two players want to play in the same console.

One of the first ones, was Drag Race, a videogame published in 1977 by Kee Games. Then we find games such as Mario Kart 64 or Goldeneye, for Nintendo 64, that also use a split screen.

When to use split screen?

You need to use the split screen when you have two players and these two players maybe are in different actions. The most common example is a race game. Maybe the first player goes 5th in the race, but the second player goes 17th. If this happens, you need to have a camera for each player because if not, one of the players couldn't play properly.

Then, we can find videogames where there are two players but there is only one camera. A clear example, is the videogame FIFA, where even if there are 4 players, it hasn't a split screen. Why? Because the action of this videogame is around the ball, so the camera will always follow the ball.

Improvements for split screen

Here I will talk about some improvements to your split screen.

Framebuffer objects

The framebuffer objects contains information such as color, depth etc. By default we render to screen, which means that if we have a texture, for example, we draw this texture to the screen directly. With the framebuffer objects, you can render to texture. Render to texture means that you render the information of color, depth to a texture.

That process it's a great benefice for your game or app, because you are generating the texture with the framebuffer object and then you render this texture.




It's very useful when you need more than one step, if you need to draw some shaders, post-processing effects, this method will save you a lot of time. In the case of a split screen, this method gives us a great perfomance because we can create framebuffer objects, draw in them, and then use the texture to draw it in the position we want. It's a little bit expensive at the beginning, but finally is much better than other option.

Camera transitions

The camera transitions are very important in videogames. In the case of the split screen, is important to make sure that the cameras are moving smooth. In some games, we find a split screen where if the two players are nearly at the same position, the two cameras join to create only one.

When the two players are separated, it appears a little transition creating a black margin between the cameras. This effect on the camera, maybe seems like a something that it isn't very important, but is a great effect to your split screen.

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.

Conclusion

Use split screen in your video game is a great idea but only if you really need it, as you could see in the page, there are examples of video games that maybe you think that would use it, but it didn't use it, so you have to be very sure about that. And if you use it, make sure to use framebuffer objects to make your game faster.

The split screen is great resource but it's also very expensive. Think that you are drawing your scene for each camera you have, and that's a hard work for your CPU.