Garry's Mod Wiki

Revision Difference

render.DrawBox#568553

<function name="DrawBox" parent="render" type="libraryfunc"> <description> Draws a box in 3D space. Draws a filled box in 3D space. ⤶ See <page>render.DrawWireframeBox</page> for a function to draw an outline of a box.⤶ <rendercontext hook="false" type="3D"></rendercontext> </description> <realm>Client</realm> <args> <arg name="position" type="Vector">Origin of the box.</arg> <arg name="angles" type="Angle">Orientation of the box.</arg> <arg name="mins" type="Vector">Start position of the box, relative to origin.</arg> <arg name="maxs" type="Vector">End position of the box, relative to origin.</arg> <arg name="color" type="Color" default="Color( 255, 255, 255 )">The color of the box.</arg> </args> </function> <example> <description>Draws a white box at the position you are looking at.</description> <code> local boxSize = Vector( 5, 5, 5 ) 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() -- white material for easy coloring cam.IgnoreZ( true ) -- makes next draw calls ignore depth and draw on top⤶ render.DrawBox( pos, angle_zero, boxSize, -boxSize, color_white ) -- draws the box cam.IgnoreZ( false ) -- disables previous call⤶ 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 ) </code> ⤶ </code> <output> <upload src="22674/8d9d79b16d43f75.png" size="860258" name="image.png" />⤶ * With WriteZ:⤶ <upload src="70c/8df3e75d3de0dcb.png" size="298569" name="image.png" />⤶ * Without WriteZ:⤶ <upload src="70c/8df3e75e3e2836a.png" size="266857" name="image.png" />⤶ </output> </example>