Skip to content

3. Blitting and clearing the viewport

theproadam edited this page Apr 2, 2020 · 2 revisions

Clearing the drawing buffer

To display an image, we must first clear the drawing buffer. As the both the drawing and depth buffers are allocated with Marshal.AllocHGlobal(), it is very important to clear them, as they are not automatically zeroed out.

//Clears the drawing buffer with black. ~0.2ms
GL.Clear();

//Clears the drawing buffer with a color. ~0.5ms
GL.Clear(R, G, B);

//Clears the depth buffer. ~0.2ms
GL.ClearDepth();

It is suggested to use the Clear(); method as it is much faster than the Clear(R, G, B); method.

Blitting the drawing buffer

Now to display the color change of the drawing buffer, the drawing buffer needs to be blitted to the form. To do this just use the Blit() function.

GL.Blit();