Vanilla path: compose effects by hand
render.SetStencilEnable(true)
-- configure a circular stencil mask here
-- the mask edge is still binary, not shader-antialiased
surface.SetDrawColor(255, 255, 255)
surface.SetMaterial(avatarMat)
surface.DrawTexturedRect(x, y, size, size)
render.SetStencilEnable(false)
draw.RoundedBox(8, x, y + 62, w, 8, track)
draw.RoundedBox(8, x, y + 62, w * hp, 8, fill)
for ox = -1, 1 do
draw.SimpleText(name, font, x + 60 + ox, y, stroke, 0, 0)
end
draw.SimpleText(name, font, x + 62, y + 2, shadow, 0, 0)
draw.SimpleText(name, font, x + 60, y, color_white, 0, 0)
MGFX path: declare the visual result
MGFX.ImageEx(x, y, size, size, avatarMat, {
fit = "cover",
mask = MGFX.Mask("circle"),
outerGlow = {color = accent, width = 12},
})
MGFX.ProgressBarEx(x, y + 62, w, 8, hp, {
radius = 4,
fill = MGFX.LinearGradient(0, 0, 1, 0, hpA, hpB),
})
MGFX.TextEx(name, font, x + 60, y, nil, 0, 0, nameStyle)
Concern
Original GMod API
MGFX
Edge quality
GMod stencil masks are binary. They can cut a shape, but they cannot produce soft shader antialiasing at the mask edge, so circles and diagonal cuts stair-step.
MGFX shape and image masks use pixel-shader coverage, so rounded boxes, circles, capsules, chamfers, rings, and strokes can keep a stable one-pixel antialiased edge.
Efficiency
Rich vanilla UI often means repeated draw.SimpleText offsets, stencil setup, several rounded-box passes, custom geometry, or render-target work for glow-like effects.
MGFX pushes supported masks, gradients, strokes, rings, bars, patterns, and text composition through immediate shader fast paths, while stable text runs are cached in atlas pages.
Surface state
You set global state with surface.SetDrawColor, surface.SetMaterial, font calls, and render state. A missed reset can leak into the next draw.
Each call carries its own fill, stroke, pattern, mask, and effect records. The visual state is local to the primitive.
Advanced image shapes
Texture draws are naturally rectangular. Circles, capsules, cut corners, and texture masks usually mean stencil setup, custom materials, or repeated helper code.
ImageEx and IconEx accept MGFX.Mask(kind, spec) for circle, capsule, chamfer, rounded, and texture masks without owning stencil plumbing at the call site.
Text effects
Shadows, strokes, glow, and fake gradient text usually become several draw.SimpleText calls per label, plus duplicated offsets in every panel.
TextEx resolves fill, stroke, glow, shadow, tracking, and line height into a reusable style while the text renderer caches composed runs.
Paint and progress UI
Bars, segmented meters, rings, arcs, striped fills, and soft glows are custom geometry or several draw passes that must be kept in sync.
ProgressBarEx, SegmentBarEx, RingEx, ArcEx, SectorEx, and gradient or pattern records keep those effects named and repeatable.
Panel and HUD boundaries
Vanilla code has no shared frame convention. Panel-local coordinates, screen-space HUD coordinates, clips, and deferred text are each handled manually.
StartPanel, StartScreen, PushClip, and the matching end calls define the frame and flush queued text at a predictable point.
Reusable visual language
The original API is intentionally low-level, so teams often copy small drawing helpers across scoreboards, HUDs, and Derma panels.
MGFX names the reusable pieces: Solid, gradients, patterns, masks, text styles, and *Ex style tables. The same record can drive many panels.
Feature fallbacks
When a shader path or visual feature is optional, your code owns every branch and every degraded version.
GetCapabilities and Supports let demos and gamemodes gate optional polish explicitly before drawing.