Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL: How to clear only a part of the screen?

Tags:

c++

opengl

Is it possible to not clear entire screen when using glClear() function? I need to clear only a part of the screen to save some rendering time, otherwise i would have to redraw half of the screen every frame, even if nothing is happening on the other half.

Of course this should be done as quickly (or quickier) as the glClear() is now.

like image 809
Newbie Avatar asked Jun 11 '10 21:06

Newbie


2 Answers

You might want to look into glScissor. From the documentation:

While scissor test is enabled, only pixels that lie within the scissor box can be modified by drawing commands.

like image 96
TreDubZedd Avatar answered Nov 17 '22 20:11

TreDubZedd


To clear only a specific rectangular region, enable ScissorTest and call Clear. Once enabled, only pixels within the scissor box will be affected by drawing commands, so disable ScissorTest when you need to modify the outside area again.

OpenTK example:

GL.Enable (EnableCap.ScissorTest);
GL.Scissor (ViewportX, ViewportY, ViewportWidth, ViewportHeight);
GL.Clear (ClearBufferMask.ColorBufferBit);
GL.Disable (EnableCap.ScissorTest);
like image 37
livin_amuk Avatar answered Nov 17 '22 20:11

livin_amuk