Garry's Mod Wiki

render.ClearStencil

render.ClearStencil()

Description

Resets all values in the stencil buffer to zero.

Example

A silly example that shows that nothing will render if you clear the stencil buffer. (From Lex's Stencil Tutorial)

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 i, ent in ipairs( ents.FindByClass( "sent_stencil_test" ) ) do ent:DrawModel() end -- Let everything render normally again render.SetStencilEnable( false ) end )
Output:

Page Links


Special Pages


Wikis

?

Render Time: 22ms

DB GetPage 4
Generate Html 1
SaveChanges (1) 9
Render Body 0
Render Sidebar 6