You use the glClear method to erase the drawing surface. Using this method, you can reset not only the color, but also the depth and the type of stencils used. You specify which element to reset by the constant that you pass in: GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, or GL_STENCIL_BUFFER_BIT.

The color buffer is responsible for the pixels that are visible, so clearing it is equivalent to erasing the surface of any colors. The depth buffer refers to all the pixels that are visible in a 3D scene, depending on how far or close the object is.

The stencil buffer is a bit advanced to cover in this introductory chapter, except to say this: you use it to create visual effects based on some dynamic criteria, and you use glClear to erase it.

Note A stencil is a drawing template that you can use to replicate a drawing many times. For example, if you are using Microsoft Office Visio, all the drawing templates that you save as *.vss files are stencils. In the noncomputer drawing world, you create a stencil by cutting out a pattern in a sheet of paper or some other flat material. Then you can paint over that sheet and remove it, creating the impression that results in a replication of that drawing.

For our purposes, you can use this code to clear the color buffer in all the examples:

//Clear the surface of any color gl.glClear(gl.GL_COLOR_BUFFER_BIT);

Now let's talk about attaching a default color to what gets drawn.

0 0

Post a comment