Garry's Mod Wiki

render.DrawLine

  render.DrawLine( Vector startPos, Vector endPos, table color = Color( 255, 255, 255 ), boolean writeZ = false )

Description

Draws a line in 3D space.

This is a rendering function that requires a 3d rendering context.

This means that it will only work in 3d Rendering Hooks.

Arguments

1 Vector startPos
Line start position in world coordinates.
2 Vector endPos
Line end position in world coordinates.
3 table color = Color( 255, 255, 255 )
The color to be used. Uses the Color.
4 boolean writeZ = false
Whether or not to consider the Z buffer. If false, the line will be drawn over everything currently drawn, if true, the line will be drawn with depth considered, as if it were a regular object in 3D space.
Enabling this option will cause the line to ignore the color's alpha.

Issue Tracker: 1086

Example

A Simple Line of code drawing a line starting for the eyes of the player and going forward.

local color_red = Color(255, 0, 0) hook.Add( "PostDrawTranslucentRenderables", "MySuper3DRenderingHook", function() local eyePos = LocalPlayer():EyePos() render.DrawLine( eyePos, eyePos + LocalPlayer():EyeAngles():Forward() * 100, color_red ) end )