Drawing Primitives
Draw 3D shapes, lines, and text using RaylibRenderer.
using Xengine.Rendering;
3D Shapes
DrawCube
void DrawCube(Vector3 position, Vector3 size, Color color)
r.DrawCube(new Vector3(0, 1, 0), Vector3.One, Color.Red);
r.DrawCube(position, new Vector3(2, 1, 0.5f), Color.Blue);
DrawCubeWires
void DrawCubeWires(Vector3 position, Vector3 size, Color color)
r.DrawCubeWires(position, new Vector3(2), Color.White);
DrawSphere
void DrawSphere(Vector3 position, float radius, Color color)
r.DrawSphere(position, 0.5f, Color.Green);
DrawSphereWires
void DrawSphereWires(Vector3 position, float radius, Color color)
DrawPlane
void DrawPlane(Vector3 position, Vector2 size, Color color)
r.DrawPlane(Vector3.Zero, new Vector2(20, 20), Color.Gray);
DrawCylinder
void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, Color color)
r.DrawCylinder(position, 0.5f, 0.5f, 2f, Color.Brown);
Lines
DrawLine3D
void DrawLine3D(Vector3 start, Vector3 end, Color color)
r.DrawLine3D(startPos, endPos, Color.Yellow);
DrawGrid
void DrawGrid(int slices, float spacing)
r.DrawGrid(20, 1f); // 20x20 grid with 1 unit spacing
Text
DrawText (2D)
void DrawText(string text, int x, int y, int fontSize, Color color)
r.DrawText("Score: 100", 10, 10, 24, Color.White);
r.DrawText($"FPS: {Time.FPS:F0}", 10, 40, 20, Color.Green);
DrawText3D
void DrawText3D(string text, Vector3 position, int fontSize, Color color)
r.DrawText3D("Player", position + new Vector3(0, 2, 0), 20, Color.White);
Using in Components
public class MyRenderer : Component
{
public Vector3 Size = Vector3.One;
public Color Color = Color.White;
protected override void OnRender(RaylibRenderer r)
{
// Draw main object
r.DrawCube(Transform.Position, Size, Color);
// Draw wireframe outline
r.DrawCubeWires(Transform.Position, Size * 1.01f, Color.Black);
// Draw shadow on ground
var shadowPos = new Vector3(Transform.Position.X, 0.01f, Transform.Position.Z);
r.DrawPlane(shadowPos, new Vector2(Size.X, Size.Z), Color.Black.WithA(0.3f));
}
}
Examples
Health Bar Above Object
protected override void OnRender(RaylibRenderer r)
{
r.DrawCube(Transform.Position, Vector3.One, Color.Red);
float healthPercent = (float)_health / _maxHealth;
var barPos = Transform.Position + new Vector3(-0.5f, 1.5f, 0);
// Background
r.DrawCube(barPos, new Vector3(1, 0.1f, 0.1f), Color.Gray);
// Health fill
r.DrawCube(barPos + new Vector3((1 - healthPercent) * -0.5f, 0, 0),
new Vector3(healthPercent, 0.1f, 0.1f), Color.Green);
}
Debug Visualization
protected override void OnRender(RaylibRenderer r)
{
// Draw velocity direction
r.DrawLine3D(Transform.Position, Transform.Position + _velocity.Normalized * 2, Color.Yellow);
// Draw detection range
r.DrawSphereWires(Transform.Position, _detectionRange, Color.Red.WithA(0.3f));
}