Garry's Mod Wiki

surface.SetMaterial

  surface.SetMaterial( IMaterial material )

Description

Sets the material to be used in all upcoming draw operations using the surface library.

Not to be confused with render.SetMaterial.

If you need to unset the texture, use the draw.NoTexture convenience function.

Material function calls are expensive to be done inside this function or inside rendering context, you should be caching the results of Material calls

Arguments

1 IMaterial material
The material to be used.
When using render.PushRenderTarget or render.SetRenderTarget, the material should have the $ignorez flag set to make it visible. If the material is not used in 3D rendering, it is probably safe to add it with this code:
material:SetInt( "$flags", bit.bor( material:GetInt( "$flags" ), 32768 ) )

If using Material, simply use the ignorez parameter.

Example

Example usage of this function in conjunction with Material. Note how the Material function will only be called once and its output is cached for performance.

In this example the .png file is located in materials/gui/ContentIcon-normal.png.

local wave = Material( "gui/ContentIcon-normal.png", "noclamp smooth" ) hook.Add( "HUDPaint", "HUDPaint_DrawATexturedBox", function() surface.SetMaterial( wave ) surface.SetDrawColor( color_white ) surface.DrawTexturedRect( 50, 50, 128, 128 ) end )