menu_bookDocumentation
Graphics.Draw, Blit, DrawText, DrawIcon, and GrabFrameTexture — Custom Rendering APIs
Graphics.Draw and Graphics.Blit: Custom Rendering in s&box
Graphics provides low-level rendering APIs for drawing custom geometry, screen-space quads, and text. All calls must happen inside a render block (e.g., OnPreRender, SceneCamera.OnRenderOverlay, or a render stage hook).Drawing Vertices
CSHARP
// Draw a list of Vertex structs
Graphics.Draw( vertices, vertCount, material );
// Draw with indices
Graphics.Draw( vertices, vertCount, indices, indexCount, material );
// Draw with custom primitive type
Graphics.Draw( vertices, vertCount, material, primitiveType: Graphics.PrimitiveType.Lines );Blit (Full-Screen Quad)
Renders a screen-space quad using a material. The material should use a screen-space shader:CSHARP
// In OnPreRender or a render hook:
Graphics.Blit( myPostProcessMaterial );DrawQuad (Screen-Space)
CSHARP
// Draw a colored quad in screen space
Graphics.DrawQuad( new Rect( 0, 0, 100, 100 ), Material.UI.Box, Color.Red );DrawText
CSHARP
// Draw text at a position
Graphics.DrawText( new Vector2( 100, 100 ), "Hello World", Color.White );
// Draw text in a rect with alignment
Graphics.DrawText( new Rect( 0, 0, 200, 50 ), "Centered", Color.White, flags: TextFlag.Center );
// Measure text without rendering
Rect size = Graphics.MeasureText( new Rect( 0, 0, 200, 50 ), "Hello" );DrawIcon (Material Icons)
CSHARP
// Draw a Material Icon (from fonts.google.com/icons)
Graphics.DrawIcon( new Rect( 10, 10, 32, 32 ), "star", Color.Yellow, fontSize: 24 );DrawRoundedRectangle
CSHARP
// Draw a rounded rectangle with optional border
Graphics.DrawRoundedRectangle(
rect: new Rect( 10, 10, 200, 100 ),
color: Color.White.WithAlpha( 0.8f ),
cornerRadius: new Vector4( 8, 8, 8, 8 ),
borderWidth: new Vector4( 2, 2, 2, 2 ),
borderColor: Color.Black
);GrabFrameTexture
Captures the current viewport's color buffer for use in post-processing:CSHARP
// In a render hook:
var frame = Graphics.GrabFrameTexture( "FrameTexture" );
// frame.ColorTarget is now available as "FrameTexture" in shader attributesImportant: Must Be Inside a Render Block
Graphics.IsActive returns true only inside a render block. Calling Graphics.Draw outside will throw. Use OnPreRender() on a component, or SceneCamera.OnRenderOverlay / OnRenderUI for screen-space rendering.
Was this helpful?