Garry's Mod Wiki

surface.SetTextColor

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

Description

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

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 'Hello World', in white, near the top left of the screen.

hook.Add( "HUDPaint", "HUDPaint_DrawABox", function() surface.SetDrawColor( 0, 0, 0, 128 ) -- Set color for background surface.DrawRect( 100, 100, 128, 20 ) -- Draw background surface.SetTextColor( 255, 255, 255 ) -- Set text color surface.SetTextPos( 136, 104 ) -- Set text position, top left corner surface.SetFont( "Default" ) -- Set the font surface.DrawText( "Hello World" ) -- Draw the text end )