Skip to content

render

color

color(r: number, g: number, b: number, a: number = 255) -> table
color(col: string) -> table

Makes a color table from rgb values or a string.

Info

String format is identical to CSS hex color format. Read more here. The only addition is that you also can specify alpha in the 4th part.

Parameters

Name Type Description
r number Red
g number Green
b number Blue
a number Alpha. Defaults to 255
Name Type Description
col string Hexadecimal color

Usage

local white = render.color(255, 255, 255);
local white = render.color('#ffffff'); -- regular way
local white = render.color('#fff'); -- short way
local white_transparent = render.color('#fff0'); -- short way with alpha value


get_screen_size

get_screen_size() -> number, number

Returns screen dimensions.

Usage

local w, h = render.get_screen_size();

create_font

create_font(path: string, size: number, flags: enum = render.font_flags_none, from: number = 0, to: number = 255) -> object

Creates a new font object from file.

Parameters

Name Type Description
path string Path to font file (ttf/otf)
size number Font height, in pixels
flags enum Additional flags. Defaults to none
from number Minimal codepoint. Defaults to 0
to number Maximal codepoint. Defaults to 255

Usage

local fnt = render.create_font('my_font.ttf', 16);

create_font_stream

create_font_stream(bytes: table[char], size: number, flags: enum = render.font_flags_none, from: number = 0, to: number = 255) -> object

Creates a new font object from char table.

Parameters

Name Type Description
bytes table[char] Font data (ttf/otf format)
size number Font height, in pixels
flags enum Additional flags. Defaults to none
from number Minimal codepoint. Defaults to 0
to number Maximal codepoint. Default to `255

Usage

local fnt = render.create_font_stream(my_font_stream, 16);

create_font_gdi

create_font_gdi(name: string, size: number, flags: enum = render.font_flags_none, from: number = 0, to: number = 255) -> object

Creates a new font object from GDI.

Parameters

Name Type Description
name string System font name
size number Font height, in pixels
flags enum Additional flags. Defaults to none
from number Minimal codepoint. Defaults to 0
to number Maximal codepoint. Default to `255

Usage

local fnt = render.create_font_gdi('Small Fonts', 8);

create_texture

create_texture(path: string) -> object

Creates a new texture from file. Supports most image formats.

Parameters

Name Type Description
path string Path to image

Usage

local tex = render.create_texture('my_texture.png');

create_texture_stream

create_texture_stream(bytes: table[char]) -> object

Creates a new texture from char table. Supports most image formats.

Parameters

Name Type Description
bytes table[char] Image stream

Usage

local tex = render.create_texture_bytes(my_texture_stream);

create_texture_bytes

create_texture_bytes(ptr: number, size: number) -> object

Creates a new texture from memory. Supports most image formats.

Note

You can get a pointer to image buffer using FFI.

Parameters

Name Type Description
ptr number Pointer to image in memory
size number Buffer size in bytes

Usage

local tex = render.create_texture_bytes(img_ptr, img_size);

create_texture_rgba

create_texture_rgba(ptr: number, w: number, h: number, stride: number) -> object

Creates a new texture from memory. Format should be RGBA stream.

Note

You can get a pointer to image buffer using FFI.

Parameters

Name Type Description
ptr number Pointer to image in memory
w number Image width
h number Image height
stride number Bytes in a row (usually w * 4)

Usage

local tex = render.create_texture_rgba(img_ptr, img_w, img_h, img_w * 4);

create_texture_svg

create_texture_svg(data: string, h: number) -> object

Creates a new texture from SVG string.

Info

If you miss <?xml header, it will be fixed automatically. However, the data must contain <svg> node!

Parameters

Name Type Description
data string SVG file contents
h number Target height

Usage

local tex = render.create_texture_svg([[
<svg style="width:24px;height:24px" viewBox="0 0 24 24">
    <path fill="#ffffff" d="M12.89,3L14.85,3.4L11.11,21L9.15,20.6L12.89,3M19.59,12L16,8.41V5.58L22.42,12L16,18.41V15.58L19.59,12M1.58,12L8,5.58V8.41L4.41,12L8,15.58V18.41L1.58,12Z" />
</svg>
]], 20);

create_shader

create_shader(src: string) -> object

Creates a new shader object.

Note

Rendering engine is using Shader Model 2, just like the game does. Keep that in mind when creating your own shaders!

Note

A shader MUST have it's entry point named main!

At this time, you can't pass your own parameters to the shader. However, you get some pre-defined ones:

Register Type Description
s0 sampler Current texture
c0 float2 Current texture's dimensions
c1 float Current time, in seconds
c2 float Current global alpha override

Parameters

Name Type Description
src string Shader source code

Usage

local shad = render.create_shader([[
    sampler s0;

    float4 main(float2 uv: TEXCOORD0): COLOR0
    {
        return tex2D(s0, uv);
    }
]]);

create_animator_float

create_animator_float(initial: number, time: number, intep: enum = render.linear) -> animator

Creates a new float animator object.

Parameters

Name Type Description
initial number Initial value
time number Animation time, in seconds
interp enum Interpolation function. Defaults to linear

Usage

local my_anim = render.create_animator_float(0, 0.5); -- this animation will take 500ms (0.5s) to finish

create_animator_color

create_animator_color(initial: table, time: number, intep: enum = render.linear, interp_hue: bool = false) -> animator

Creates a new color animator object.

Parameters

Name Type Description
initial table Initial value
time number Animation time, in seconds
interp enum Interpolation function. Defaults to linear
interp_hue bool If true, will animate by hue value instead of RGB. Defaults to false

Usage

local my_anim = render.create_animator_color(render.color('#fff'), 0.5); -- this animation will take 500ms (0.5s) to finish

push_texture

push_texture(id: number)

Pushes a texture to stack.

Deprecated

This function is deprecated and will be removed in future updates. Use set_texture instead.

Parameters

Name Type Description
id number Texture ID

Usage

render.push_texture(my_tex);

pop_texture

pop_texture()

Pops a texture from stack.

Deprecated

This function is deprecated and will be removed in future updates. Use set_texture instead.

Usage

render.pop_texture();

push_clip_rect

push_clip_rect(x1: number, y1: number, x2: number, y2: number, intersect: bool = true)

Pushes a clip rect to stack.

Parameters

Name Type Description
x1 number Top left X
y1 number Top left Y
x2 number Bottom right X
y2 number Bottom right Y
intersect bool Whether should intersect clip rect with a previous one. Defaults to true

Usage

render.push_clip_rect(5, 5, 150, 150);

pop_clip_rect

pop_clip_rect()

Pops a clip rect from stack.

Usage

render.pop_clip_rect();

push_uv

push_uv(x1: number, y1: number, x2: number, y2: number)

Pushes a UV rect to stack.

Deprecated

This function is deprecated and will be removed in future updates. Use set_uv instead.

Parameters

Name Type Description
x1 number Top left X
y1 number Top left Y
x2 number Bottom right X
y2 number Bottom right Y

Usage

render.push_clip_rect(0.0, 0.0, 0.5, 0.5);

pop_uv

pop_uv()

Pops a UV rect from stack.

Deprecated

This function is deprecated and will be removed in future updates. Use set_uv instead.

Usage

render.pop_uv();

push_alpha

push_alpha(alpha: number)

Pushes an alpha override to stack.

Deprecated

This function is deprecated and will be removed in future updates. Use set_alpha instead.

Parameters

Name Type Description
alpha number New alpha value (0.0 to 1.0)

Usage

render.push_alpha(0.5);

pop_alpha

pop_alpha()

Pops an alpha override from stack.

Deprecated

This function is deprecated and will be removed in future updates. Use set_alpha instead.

Usage

render.pop_alpha();

set_texture

set_texture(texture: object / nil)

Sets a texture to be used.

Parameters

Name Type Description
texture object / nil Texture

Usage

render.set_texture(my_tex);
render.rect_filled(50, 50, 150, 150, render.color('#fff'));
render.set_texture(nil);

set_uv

set_uv(x1: number, y1: number, x2: number, y2: number)

Sets UV parameters for the current texture.

Info

You can read what UV is here.

Tip

UV values are from 0.0 (top or left) to 1.0 (bottom or right). If you wish to get a part from texture using pixels, divide your value by width or height of a texture.

Parameters

Name Type Description
x1 number X1 parameter (0.0 to 1.0)
y1 number Y1 parameter (0.0 to 1.0)
x2 number X2 parameter (0.0 to 1.0)
y2 number Y2 parameter (0.0 to 1.0)

Usage

render.set_uv(0, 0, 0.5, 0.5); -- only top left quarter of the texture 
                               -- will be rendered

set_uv

set_uv(nil)

Resets UV parameters back to default.

Info

You can read what UV is here.

Usage

render.set_uv(nil);

set_alpha

set_alpha(mod: number)

Overrides global alpha value. Set to 1.0 to reset.

Parameters

Name Type Description
mod number Alpha to set (0.0 to 1.0)

Usage

render.set_alpha(0.5);

set_rotation

set_rotation(rot: number)

Sets rotation override.

Warning

Some figures ignore this parameter.

Parameters

Name Type Description
rot number Rotation, in degrees

Usage

render.set_rotation(90); -- will rotate next figure by 90deg

set_shader

set_shader(shader: object / nil)

Sets or resets a shader.

Parameters

Name Type Description
shader object / nil Shader

Usage

render.set_shader(shad);

get_texture_size

get_texture_size(texture: object) -> number, number

Returns texture dimensions.

Parameters

Name Type Description
texture object Texture

Usage

local w, h = render.get_texture_size(my_tex);

get_frame_count

get_frame_count(texture: object) -> number

Returns frame count of the animated GIF.

Warning

This function will return 0 if a texture is NOT an animated GIF.

Parameters

Name Type Description
texture object Texture

Usage

local frames = render.get_frame_count(my_gif);

set_frame

set_frame(texture: object, frame: number)

Sets current frame for the animated GIF.

Parameters

Name Type Description
texture object Texture
frame number Target frame

Usage

render.set_frame(my_gif, 5);

set_loop

set_loop(texture: object, val: bool)

Toggles looping for the animated GIF.

Parameters

Name Type Description
texture object Texture
val bool true to enable looping, false to disable

Usage

render.set_loop(my_gif, false);

reset_loop

reset_loop(texture: object)

Starts texture loop from the frame 0.

Parameters

Name Type Description
texture object Texture

Usage

render.reset_loop(my_gif);

get_text_size

get_text_size(font: object, text: string) -> number, number

Returns text dimensions.

Parameters

Name Type Description
font object Font
text string Text

Usage

local w, h = render.get_text_size(my_fnt, 'Hello world!');

wrap_text

wrap_text(font: object, text: string, width: number) -> string

Wraps text by width (inserting new lines if a word is exceeding target width). Can be resource intensive at times.

Parameters

Name Type Description
font object Font
text string Text
width number Target width

Usage

local text = render.wrap_text(my_fnt, 'This is a really long string!', 250);

rect

rect(x1: number, y1: number, x2: number, y2: number, color: table, thickness: number = 1.0)

Renders a rectangle.

Parameters

Name Type Description
x1 number X1 position
y1 number Y1 position
x2 number X2 position
y2 number Y2 position
color table Color
thickness number Line thickness. Defaults to 1.0

Usage

render.rect(50, 50, 150, 150, render.color('#fff'));

rect_filled

rect_filled(x1: number, y1: number, x2: number, y2: number, color: table)

Renders a filled rectangle.

Parameters

Name Type Description
x1 number X1 position
y1 number Y1 position
x2 number X2 position
y2 number Y2 position
color table Color

Usage

render.rect_filled(50, 50, 150, 150, render.color('#fff'));

rect_filled_rounded

rect_filled_rounded(x1: number, y1: number, x2: number, y2: number, color: table, rounding: number, sides: enum = all)

Renders a filled rounded rectangle.

Parameters

Name Type Description
x1 number X1 position
y1 number Y1 position
x2 number X2 position
y2 number Y2 position
color table Color
rounding number Corner rounding
sides enum Sides to round. Defaults to render.all

Usage

render.rect_filled(50, 50, 150, 150, render.color('#fff'), 10);

render_filled_multicolor

render_filled_multicolor(x1: number, y1: number, x2: number, y2: number, tl: table, tr: table, br: table, bl: table)

Renders a filled multicolor rectangle.

Parameters

Name Type Description
x1 number X1 position
y1 number Y1 position
x2 number X2 position
y2 number Y2 position
tl table Top left color
tr table Top right color
br table Bottom right color
bl table Bottom left color

Usage

local c1, c2 = render.color('#fff'), render.color('#000');
render.rect_filled_multicolor(50, 50, 150, 150, c1, c1, c2, c2);

circle

circle(x: number, y: number, radius: number, color: table, thickness: number = 1.0, segments: number = 12, fill = 1.0, rot = 0.0)

Renders a circle.

Parameters

Name Type Description
x number Center X position
y number Center Y position
radius number Radius
color table Color
thickness number Line thickness. Defaults to 1.0
segments number Circle segments. Defaults to 12
fill number Fill value. Accepts values from 0.0 to 1.0. Defaults to 1.0
rot number Circle rotation, in degrees. Defaults to 0.0

Usage

render.circle(50, 50, 10, render.color('#fff'));

circle_filled

circle_filled(x: number, y: number, radius: number, color: table, segments: number = 12, fill = 1.0, rot = 0.0)

Renders a filled circle.

Parameters

Name Type Description
x number Center X position
y number Center Y position
radius number Radius
color table Color
segments number Circle segments. Defaults to 12
fill number Fill value. Accepts values from 0.0 to 1.0. Defaults to 1.0
rot number Circle rotation, in degrees. Defaults to 0.0

Usage

render.circle_filled(50, 50, 10, render.color('#fff'));

line

line(x1: number, y1: number, x2: number, y2: number, color: table)

Renders a line.

Parameters

Name Type Description
x1 number X1 position
y1 number Y1 position
x2 number X2 position
y2 number Y2 position
color table Color

Usage

render.line(50, 50, 150, 150, render.color('#fff'));

triangle

triangle(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, color: table)

Renders a triangle.

Parameters

Name Type Description
x1 number X1 position
y1 number Y1 position
x2 number X2 position
y2 number Y2 position
x3 number X3 position
y3 number Y3 position
color table Color

Usage

render.triangle(50, 50, 150, 150, 100, 100, render.color('#fff'));

triangle_filled

triangle_filled(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, color: table)

Renders a filled triangle.

Parameters

Name Type Description
x1 number X1 position
y1 number Y1 position
x2 number X2 position
y2 number Y2 position
x3 number X3 position
y3 number Y3 position
color table Color

Usage

render.triangle(50, 50, 150, 150, 100, 100, render.color('#fff'));

triangle_filled_multicolor

triangle_filled_multicolor(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, a: table, b: table, c: table)

Renders a filled multicolor triangle.

Parameters

Name Type Description
x1 number X1 position
y1 number Y1 position
x2 number X2 position
y2 number Y2 position
x3 number X3 position
y3 number Y3 position
a table A color
b table B color
c table C color

Usage

render.triangle(50, 50, 150, 150, 100, 100, render.color('#fff'), render.color('#000'), render.color('#000'));

text

text(font: object, x: number, y: number, text: string, color: table, ah: enum = left, av: enum = top, al: enum = left)

Renders a text.

Parameters

Name Type Description
font object Font
x number X position
y number Y position
text string Text
color table Color
ah enum Horizontal alignment
av enum Vertical alignment
al enum Line alignment

Usage

render.text(my_fnt, 50, 50, 'Hello world!', render.color('#fff'));

blur

blur(x1: number, y1: number, x2: number, y2: number, fn: ())

Blurs a figure.

Warning

This function can be VERY resource intensive. Make sure that you only have a SINGLE figure call in the function!

Tip

Use render.set_alpha to control intensity of the blur.

Parameters

Name Type Description
x1 number Figure box X1 position
y1 number Figure box Y1 position
x2 number Figure box X2 position
y2 number Figure box Y2 position
fn function() Figure render callback

Usage

render.blur(50, 50, 150, 150, function ()
    render.rect_filled(50, 50, 150, 150, render.color('#fff'));
end);