Garry's Mod Wiki

surface.SetDrawColor

  surface.SetDrawColor( number r, number g, number b, number a = 255 )
  surface.SetDrawColor( table color )

Description

Set the color of any future shapes to be drawn, can be set by either using R, G, B, A as separate values or by a Color.

The alpha value may not work properly if you're using a material without $vertexalpha.
Due to post processing and gamma correction the color you set with this function may appear differently when rendered. This problem does not occur on materials drawn with surface.DrawTexturedRect.

Default Arguments

1 number r
The red value of color.
2 number g
The green value of color.
3 number b
The blue value of color.
4 number a = 255
The alpha value of color.

Argument Overload: Use color object

1 table color
A Color object/table to read the color from. This is slower than providing four numbers. You could use Color:Unpack to address this. You should also cache your color objects if you wish to use them, for performance reasons.

Example

Draws a 512x512 textured rectangle with the wireframe material.

local myMaterial = Material( "models/wireframe" ) -- Calling Material() every frame is quite expensive hook.Add( "HUDPaint", "example_hook", function() surface.SetDrawColor( 255, 0, 0 ) -- Set the color to red surface.SetMaterial( myMaterial ) -- If you use Material, cache it! surface.DrawTexturedRect( 0, 0, 512, 512 ) end )