Skip to content

Graphics

Load shaders, create meshes, draw, and set view/projection matrices. All methods are static.

Returns: Shader or null — Loaded shader, or null if the shader could not be loaded.

Parameters:

  • path (String) — Path to the shader without extension (e.g. "shaders/triangle"). The engine loads the corresponding .spv file from the mounted filesystem.

Same path returns the same cached instance. In dev with hot-reload, changing the source may trigger a recompile.

var shader = Graphics.loadShader("shaders/triangle")
if (shader != null) {
Graphics.useShader(shader)
_mesh = Graphics.newMesh(vertices, "triangles", shader)
}

Parameters:

  • shader (Shader) — Shader to use for subsequent draw calls.

Set the current shader. Subsequent drawMesh calls use this shader unless overridden.

Graphics.useShader(myShader)
Graphics.drawMesh(_mesh)

Returns: Mesh — A new mesh.

Parameters:

  • vertices (List) — List of vertex data. Each vertex is typically a list of 7 numbers: [x, y, z, r, g, b, a] (position + color).
  • drawMode (String) — One of "triangles", "trianglestrip", "lines", "linestrip", "lineloop", "points".

Graphics.newMesh(vertices, drawMode, shader)

Section titled “Graphics.newMesh(vertices, drawMode, shader)”

Returns: Mesh — A new mesh associated with the given shader.

Parameters:

  • vertices (List) — Same as above.
  • drawMode (String) — Same as above.
  • shader (Shader) — Shader to use when drawing this mesh.
_mesh = Graphics.newMesh([
[0.0, -0.5, 0.0, 1.0, 0.0, 0.0, 1.0],
[0.5, 0.5, 0.0, 0.0, 1.0, 0.0, 1.0],
[-0.5, 0.5, 0.0, 0.0, 0.0, 1.0, 1.0]
], "triangles", shader)

Graphics.drawMesh(mesh) / Graphics.drawMesh(mesh, shader) / Graphics.drawMesh(mesh, shader, modelMatrix)

Section titled “Graphics.drawMesh(mesh) / Graphics.drawMesh(mesh, shader) / Graphics.drawMesh(mesh, shader, modelMatrix)”

Parameters:

  • mesh (Mesh) — Mesh to draw.
  • shader (Shader, optional) — Override the current or mesh shader.
  • modelMatrix (optional) — Model matrix for the draw.

Draw a mesh this frame. With one argument, uses the mesh’s shader or the current shader. With two, uses the given shader. With three, also applies the model matrix.

Graphics.drawMesh(_mesh)
Graphics.drawMesh(_mesh, otherShader)

Parameters:

  • matrix — View matrix (camera world-to-view transform). Format is implementation-dependent (e.g. list or foreign type).

Set the view matrix used for subsequent drawing (when view/projection is enabled).

Parameters:

  • matrix — Projection matrix. Format is implementation-dependent.

Set the projection matrix.

Graphics.setViewProjectionEnabled(enabled)

Section titled “Graphics.setViewProjectionEnabled(enabled)”

Parameters:

  • enabled (Bool) — true to use the current view and projection matrices; false to draw without them (e.g. full-screen UI).

Enable or disable application of view and projection matrices (e.g. for 3D scene vs. UI).

Graphics.setViewProjectionEnabled(true)
Graphics.setViewMatrix(camera.getViewMatrix())
Graphics.setProjectionMatrix(camera.getProjectionMatrix(aspect))
_scene.draw()