35

The stencil buffer definition by Wikipedia is indeed not great, it focuses too much on the details of modern implementations (OpenGL). I find the disambiguated version easier to understand: A stencil is a template used to draw or paint identical letters, symbols, shapes, or patterns every time it is used. The design produced by such a template is also ...


13

The stencil buffer is an unsigned integer buffer, usually 8-bit nowadays, where you can fill per-pixel infomation as you wish based on the use of various operations (OpenGL Ops here for example) following a stencil test. The stencil test is simply a per-pixel operation in which the current pixel stencil value is tested against the content of the stencil ...


11

The original use for the stencil buffer was for non-3D content. Say you're making a 3D game. Most of the screen is the 3D content, but you also have some GUI around the outside which is not drawn through OpenGL but through a 2D canvas API. You can mask off the shape of the 2D GUI using the stencil buffer, and then make sure that your 3D/OpenGL content won't ...


6

A stencil buffer contains per-pixel integer data which is used to add more control over which pixels are rendered. A stencil buffer operates similarly to a depth buffer. So similarly, that stencil data is stored in a depth buffer. While depth data determines which pixel is closest to the camera, stencil data can be used as a more general purpose ...


5

Another use, that I think Dan didn't mention, is for filling non-convex polygons, e.g, and The stencil can be used to implement the fill rule which is typically either odd/even (as used in these examples) or non-zero, simply by, say, treating the list of vertices as a triangle fan or, with reordering, a triangle strip, and setting the stencil ...


2

OK, so this not really an answer, rather just sharing what I have learned. To clarify, shape of the object has nothing to do with this problem at all. Be it a triangle or rectangle, and wherever you click on that object, this method should work (the 'But' for this part is explained below). I think stencil buffer values are associated with each pixel on ...


1

It sounds like what you need is a scissor test. It's specifically designed for clipping against an unrotated rectangle, and should be faster than messing about with the stencil buffer.


Only top voted, non community-wiki answers of a minimum length are eligible