render.ClearStencil

From Garry's Mod
Jump to: navigation, search
 render.ClearStencil( )

Description

Resets all values in the stencil buffer to zero.

Examples

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 _, ent in pairs( ents.FindByClass( "sent_stencil_test" ) ) do
		ent:DrawModel()
	end

	-- Let everything render normally again
	render.SetStencilEnable( false )
end )

Output:

stencil clearbuffer result.jpg
Personal tools
Navigation