Kubajzz's picture

Multiple viewports in one glControl

I need to show several views of a model in the same window. I originally used several glControls, but then I decided to use only one glControl and render to different viewports. However, the thing does not work...

I call the following code 4 times from the Paint event of the glControl:

GL.Viewport(region); // "region" is a Rectangle that represents the corresponding region on the screen
 
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
 
// Set projection and modelview matrices
 
// Draw my model
 
control.SwapBuffers();

After this code runs, only the last drawn region is correctly displayed, the others are empty. I found out that when I call GL.Clear(ClearBufferMask.ColorBufferBit), the whole glControl is cleared instead of clearing only the region set by GL.Viewport(). How do I fix this?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Hortus Longus's picture

Simply change the lines. ;-)

GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.Viewport(region1);
// Draw
GL.Viewport(region2);
// Draw
GL.Viewport(region3);
// Draw
GL.Viewport(region4);
// Draw
control.SwapBuffers();
nythrix's picture
Quote:

I found out that when I call GL.Clear(ClearBufferMask.ColorBufferBit), the whole glControl is cleared instead of clearing only the region set by GL.Viewport(). How do I fix this?

You have to enable scissor test: GL.Enable( EnableCap.ScissorTest );
then use it together with GL.Viewport: GL.Scissor( region );

Kubajzz's picture

Thanks for your replies guys!

The Hortus' method looks like the best and the simplest solution in my case. Thanks nytrix for the GL.Scissor tip though, I didn't know about that function.