Returns the width and height of the canvas in pixels.
local w, h = lge.get_canvas_size()Clears the canvas to a solid color.
color: String, hex RGB of the form"#rrggbb". Default is black ("#000000").
-- Clear to black
lge.clear_canvas()
-- Clear to dark gray
lge.clear_canvas("#202020")Draws a filled circle.
x, y: Center position in canvas coordinates.radius: Circle radius in pixels.color: String,"#rrggbb".
lge.draw_circle(100, 100, 20, "#ff0000")Draws a filled rectangle.
x, y: Top-left corner in canvas coordinates.width, height: Size in pixels.color: String,"#rrggbb".
lge.draw_rectangle(100, 100, 20, 40, "#ff0000")Draws a filled triangle.
(x0, y0),(x1, y1),(x2, y2): Vertex coordinates in canvas space.color: String,"#rrggbb".
lge.draw_triangle(100, 100, 100, 200, 200, 200, "#ff0000")Draws a string of text.
x, y: Text position in canvas coordinates.text: Lua string.color: String,"#rrggbb".
lge.draw_text(10, 20, "Score: 42", "#ffffff")- Camera is at
(0, 0, 0). - Camera looks along the +Z axis.
x: horizontal,y: vertical,z: depth.- Objects with
z <= 0are behind the camera and not visible. - World units are arbitrary but consistent across position, bounds, and radius/scale.
Configures the 3D camera and projection parameters.
fov: Projection factor / effective field-of-view (positive number).cam_distance: Distance / scale factor used in projection.
Call this at startup or whenever the camera configuration changes.
local FOV = 220
local CAM_DISTANCE = 180
lge.set_3d_camera(FOV, CAM_DISTANCE)Sets a single directional light.
dx, dy, dz: Direction vector in world space. It is recommended that this be normalized.ambient: Ambient light strength (typically0.0–1.0).diffuse: Diffuse light strength (typically0.0–1.0).
-- Light from above and slightly toward the camera
lge.set_3d_light(0, 1, -1, 0.2, 0.8)You can update the light dynamically (for example, based on mouse position) each frame.
Registers a static 3D triangle mesh.
-
vertices: Flat Lua array of numbers, grouped as(x, y, z)triples. Example:{x1, y1, z1, x2, y2, z2, ...} -
faces: Flat Lua array of integers, grouped as triangles(i1, i2, i3). Indices are 1-based, each index referring to a vertex triple invertices.
Returns:
model_id: An opaque identifier used withlge.create_3d_instance.
local vertices = {
0.0, 0.0, 0.0,
1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
}
local faces = {
1, 2, 3,
}
local model_id = lge.create_3d_model(vertices, faces)Creates a renderable instance of a 3D model with per-triangle colors.
model_id: Returned fromlge.create_3d_model.tri_colors: Lua array of strings, one color per triangle in the model. Length must equal(#faces / 3)for that model.
Returns:
instance_id: Opaque identifier used withlge.draw_3d_instance.
local tri_colors = {
"#ff0000", -- triangle 1
"#00ff00", -- triangle 2
"#0000ff", -- triangle 3
}
local instance_id = lge.create_3d_instance(model_id, tri_colors)Draws a 3D instance in the current frame.
instance_id: Fromlge.create_3d_instance.x, y, z: World-space position of the instance’s center.radius: Uniform scale factor (world units).angle_x, angle_y, angle_z: Rotation about local X/Y/Z axes, in radians.
lge.draw_3d_instance(
instance_id,
0.0, 0.0, 150.0, -- position
20.0, -- radius / scale
0.0, 0.5, 0.0 -- rotation
)Call this for each instance you want to render in a frame, after updating their positions and rotations.
Returns information about the most recent mouse click.
button: Integer or engine-specific constant indicating which button was pressed.x, y: Click position in canvas coordinates.- If no click is pending, returns
nil. - Once read, the stored click is cleared until a new click occurs.
local button, x, y = lge.get_mouse_click()
if x then
-- Handle click at (x, y)
endReturns the current mouse position.
button: Button state (if provided).x, y: Current cursor position in canvas coordinates.- If the mouse position is unavailable, returns
nil.
local button, x, y = lge.get_mouse_position()
if x then
lge.draw_circle(x, y, 10, "#00ffff")
endDelays execution for the given number of milliseconds, yielding the coroutine and allowing the engine to process events / timing.
ms: Delay duration in milliseconds.
-- Small delay to pace the loop
lge.delay(1)Swaps or presents the current canvas buffer to the display. Typically called once per frame, after all drawing calls.
while true do
lge.clear_canvas("#000000")
-- draw stuff...
lge.present()
lge.delay(1)
endReturns the current frames-per-second as a floating-point value.
local fps = lge.fps()
fps = math.floor(fps * 100 + 0.5) / 100
lge.draw_text(5, 5, "FPS: " .. fps, "#ffffff")This is a minimal example that:
- Sets up the camera and a light.
- Creates a simple 3D model (one triangle).
- Spins it in 3D and draws FPS text.
-- Seed any RNG you might have (optional)
-- math.randomseed(...)
-- 1. Setup
local SCREEN_W, SCREEN_H = lge.get_canvas_size()
-- Camera (camera at origin, looking along +Z)
local FOV = 220
local CAM_DISTANCE = 180
lge.set_3d_camera(FOV, CAM_DISTANCE)
-- Light: from above, slightly towards the camera
local LIGHT_AMBIENT = 0.2
local LIGHT_DIFFUSE = 0.8
lge.set_3d_light(0, 1, -1, LIGHT_AMBIENT, LIGHT_DIFFUSE)
-- 2. Create a simple 3D model: one triangle
local vertices = {
-0.5, -0.5, 0.0,
0.5, -0.5, 0.0,
0.0, 0.5, 0.0,
}
local faces = {
1, 2, 3,
}
local model_id = lge.create_3d_model(vertices, faces)
-- Per-triangle colors (only 1 triangle here)
local tri_colors = { "#ff0000" }
local instance_id = lge.create_3d_instance(model_id, tri_colors)
-- 3. Animation state
local angle_x = 0
local angle_y = 0
local angle_z = 0
-- Position it in front of the camera
local pos_x = 0
local pos_y = 0
local pos_z = 150
local radius = 40
-- 4. Main loop
while true do
-- Clear background
lge.clear_canvas("#000000")
-- Update rotation
angle_x = angle_x + 0.01
angle_y = angle_y + 0.02
angle_z = angle_z + 0.015
-- Draw 3D instance
lge.draw_3d_instance(
instance_id,
pos_x, pos_y, pos_z, -- world position
radius, -- scale
angle_x, angle_y, angle_z
)
-- Draw FPS
local fps = lge.fps()
fps = math.floor(fps * 100 + 0.5) / 100
lge.draw_text(5, 5, "FPS: " .. fps, "#ffffff")
-- Present frame
lge.present()
lge.delay(1)
end