Revision Difference
render.ClearStencil#527930
<function name="ClearStencil" parent="render" type="libraryfunc">
<description>Resets all values in the stencil buffer to zero.</description>
<realm>Client</realm>
</function>
<example>
<description>
A silly example that shows that nothing will render if you clear the stencil buffer. (From
[Lex's Stencil Tutorial](https://github.com/Lexicality/stencil-tutorial))
</description>
<code>
hook.Add( "PostDrawOpaqueRenderables", "Stencil Tutorial Example", function()
-- Reset everything to known good
render.SetStencilWriteMask( 0xFF )
render.SetStencilTestMask( 0xFF )
render.SetStencilReferenceValue( 0 )
render.SetStencilCompareFunction( STENCIL_ALWAYS )
render.SetStencilPassOperation( STENCIL_KEEP )
render.SetStencilFailOperation( STENCIL_KEEP )
render.SetStencilZFailOperation( STENCIL_KEEP )
-- Enable stencils
render.SetStencilEnable( true )
-- Set the reference value to 1. This is what the compare function tests against
render.SetStencilReferenceValue( 1 )
-- Refuse to write things to the screen unless that pixel's value is 1
render.SetStencilCompareFunction( STENCIL_EQUAL )
-- Set the entire screen to 0
render.ClearStencil()
-- Attempt to draw our entities. Nothing will draw, because nothing in the buffer is 1.
for _, ent in pairs( ents.FindByClass( "sent_stencil_test" ) ) do
for i, ent in ipairs( ents.FindByClass( "sent_stencil_test" ) ) do
ent:DrawModel()
end
-- Let everything render normally again
render.SetStencilEnable( false )
end )
</code>
<output><image src="stencil_clearbuffer_result.jpg" alt="left|400px"/></output>
</example>