Multiple viewports with modern OpenGL? I use SDL2.

Currently my only shader has a MVP matrix, and transforms the points with it.

I calculate my View and Projection matrix for a camera with GLM:

glm::lookAt(pos, pos + forward, up);
glm::perspective(fov, aspectRatio, zNear, zFar);


I searched it, but I can only find legacy implementation of multiple viewports.

If I create for example 4 cameras and let's say that they all the same, except every camera has a different quarter of the screen to render. (So I want 4 viewports with the same content)

How can I do this? Sorry if I didn't give enough informations, feel free to ask.
If you are writing your own Vertex/Fragment Shader there is another additional possibility to do this. It is much more complicated but might be useful for you and/or others. Additionally it speeds up the whole drawing process since it uses only one call to a draw command. The maximum number of Viewports is defined by GL_MAX_VIEWPORTS and is usually 16. 

Since OpenGL 4.1 the method glViewportArrayv exists. It can define an array of Viewports. The Viewports which are created by this method have an index assigned. 

This index can be used in the Vertex Shader to set the Viewport to which the scene is rendered. (You have to include the "ARB_shader_viewport_layer_array" extension in the shader code)

In your case I would suggest to do the following:


Store the 4 camera matrices in a Shader Storage Buffer (Array of mat4) to have them in the Vertex Shader
Use indexed drawing, for example :glDrawElementsInstanced
use the build in gl_InstanceID of the Vertex Shader to access the camera matrix array
set the build in variable output variable gl_ViewportIndex in the Fragment Shader to the gl_InstanceID. (for details see ARB_fragment_layer_viewport)