Garry's Mod Wiki

render.DrawBox

  render.DrawBox( Vector position, Angle angles, Vector mins, Vector maxs, Color color = Color( 255, 255, 255 ) )

Description

Draws a filled box in 3D space.

See render.DrawWireframeBox for a function to draw an outline of a box.

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 position
Origin of the box.
2 Angle angles
Orientation of the box.
3 Vector mins
Start position of the box, relative to origin.
4 Vector maxs
End position of the box, relative to origin.
5 Color color = Color( 255, 255, 255 )
The color of the box.

Example

Draws a white box at the position you are looking at.

local boxSize = Vector( 10, 10, 10 ) local boxColor = Color( 255, 255, 255, 100 ) local writeZ = true hook.Add( "PostDrawTranslucentRenderables", "Boxxie", function() local pos = LocalPlayer():GetEyeTrace().HitPos -- position to render box at render.SetColorMaterial() -- material for coloring if ( !writeZ ) then cam.IgnoreZ( true ) end render.DrawBox( pos, angle_zero, -boxSize, boxSize, boxColor ) if ( !writeZ ) then cam.IgnoreZ( false ) end end )
Output:
  • With WriteZ:
image.png
  • Without WriteZ:
image.png