Drawing works inside events.present_queue, events.menu and custom controls. render.layer("foreground") draws over the menu, render.layer("background") (default) under it. Fonts: regular, bold, small, big, verdana, verdana_bold, mono, title, hud, hud_small, brand, icons, at any size. Text flags: c center x, r right, m center y, b bottom, o outline, s shadow.
render (numbers, x y w h)#
| Function | Parameters | Returns | Description |
|---|---|---|---|
render.text(x, y, text, color, font?, size?, flags?) | flags: string such as "co" | none | Also render.text(font, text, x, y, color, size, centered). |
render.text_size(text, font?, size?) | w, h | Also render.measure_text(font, text, size). | |
render.line(x1, y1, x2, y2, color, thickness?) | none | render.line_gradient(..., c1, c2, thickness) | |
render.rect(x, y, w, h, color, rounding?, thickness?) | none | Outline. | |
render.rect_filled(x, y, w, h, color, rounding?) | none | ||
render.rect_filled_gradient(x, y, w, h, c1, c2, angle?) | angle: 0, 90, 180, 270 | none | Also render.gradient(x, y, w, h, c1, c2, horizontal). |
render.circle(x, y, r, color, thickness?, segments?) | none | render.circle_filled, render.circle_filled_gradient(x, y, r, inner, outer) | |
render.arc(x, y, r, from, to, color, thickness?) | degrees | none | render.arc_filled |
render.triangle(x1, y1, x2, y2, x3, y3, color) | none | render.triangle_filled | |
render.poly(points, color, thickness?, closed?) | flat {x1, y1, ...} or Vec2 list | none | render.poly_filled(points, color) (convex) |
render.image(texture, x, y, w, h, tint?, rounding?) | none | Textures: render.create_texture(path), create_texture_rgba(data, w, h), create_texture_from_memory(bytes). | |
render.shadow_rect(x, y, w, h, color, size, ox?, oy?) | none | render.shadow_circle | |
render.push_clip(x, y, w, h, intersect?) | none | render.pop_clip() | |
render.world_to_screen(vector) | or (x, y, z) | x, y or nil | nil when the point is behind the camera. |
render.screen_size() | w, h | ||
render.line_3d(a, b, color, thickness?) | Vectors | none | World space. |
render.circle_3d(center, radius, color, segments?, thickness?, fill?) | none | Flat circle on the ground. | |
render.box_3d(mins, maxs, color, thickness?) | none | ||
render.text_3d(pos, text, color, font?, size?, flags?) | none | ||
render.create_font(name, size, flags?) | font | Built-in fonts at any size. |
events.present_queue:add(function()
local me = entity.get_local_player()
if not me then return end
local x, y = render.world_to_screen(me:get_abs_origin())
if x then
render.text(x, y, "local player", Color(255, 255, 255), "bold", nil, "co")
end
render.circle_3d(me:get_abs_origin(), 32, Color(140, 120, 255), 48, 2)
end)draw.surface (Vec2, Rect and Color objects)#
draw.surface is a drawing layer with a font field. Methods: add_text(pos, text, color, params), add_line, add_line_multicolor, add_rect, add_rect_filled, add_rect_rounded, add_rect_filled_rounded, add_rect_filled_multicolor(rect, {tl, tr, br, bl}), add_circle(center, radius, color, segments, fill, thickness), add_circle_filled, add_circle_filled_multicolor, add_triangle, add_triangle_filled, add_triangle_filled_multicolor, add_quad, add_quad_filled, add_quad_filled_multicolor, add_pill_multicolor, add_shadow_line, add_shadow_rect, add_glow, add_image, add_polyline, add_poly_filled, override_clip_rect(rect or nil). Helpers: draw.Rect, draw.Vec2, draw.Color, draw.fonts, draw.Font(name, size), draw.Texture(path), draw.TextParams, draw.TextAlignment, draw.Rounding, draw.GetDisplay(), draw.GetTime().
events.present_queue:add(function()
local d = draw.surface
d.font = draw.fonts.bold
d:add_rect_filled_rounded(draw.Rect(20, 20, 220, 50), Color(15, 15, 20, 220), 6)
d:add_text(Vec2(120, 35), "centered", Color.White(), draw.TextParams.with_vh(draw.TextAlignment.CENTER, draw.TextAlignment.CENTER))
end)