Rendering to different viewports (parts) of the same screen can be easily done with blending. As far as I know GL_BLEND
or glBlendFunc
isn't considered legacy.follows:
For example splitting screen into four parts and rendering the same scene four times to each corner with different uniforms and different viewports:
bindFramebuffer();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
scene->setConstPerFrameUniforms();
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
//left bottom
glViewport(0, 0, WindowWidth*0.5, WindowHeight*0.5);
scene->setVarPerFrameUniforms(1);
scene->draw();
//right bottom
glViewport(WindowWidth*0.5, 0, WindowWidth*0.5, WindowHeight*0.5);
scene->setVarPerFrameUniforms(2);
scene->draw();
//left top
glViewport(0, WindowHeight*0.5, WindowWidth*0.5, WindowHeight*0.5);
scene->setVarPerFrameUniforms(3);
scene->draw();
//right top
glViewport(WindowWidth*0.5, WindowHeight*0.5, WindowWidth*0.5, WindowHeight*0.5);
scene->setVarPerFrameUniforms(4);
scene->draw();
glViewport(0, 0, WindowWidth, WindowHeight); //restore default
glDisable(GL_BLEND);
This use GL_ONE, GL_ONE
blend mode but for some effects like overlapping different modes can be used. This is nice visual representation of different modes
EDIT:
I thought about that and it can be done without blending. You just need four framebuffers or one with bunch of color attachments. To each of them you render your scene with different viewport enabled. Then in render pass to screen you bind those textures and blend them in more modern way using fragment shader. That's more complex but with more freedom of applying desired results.