natiny.backend.init

Lua
natiny.backend.init([backend]) -> ok

Chooses the graphics backend and prepares the engine to draw with it. Call it before APIs that require an initialized engine.

Parameters

Name Type Default Description
backend number or string natiny.backend.AUTO Backend constant below or its string name

Constants

Constant String Platforms
natiny.backend.AUTO "auto" The platform's first choice
natiny.backend.D3D12 "d3d12" Windows
natiny.backend.VULKAN "vulkan" Windows, Linux
natiny.backend.OPENGL "opengl" Windows, Linux
natiny.backend.METAL "metal" macOS, iOS
natiny.backend.WEBGPU "webgpu" Web
natiny.backend.GLES "gles" Web, Android, iOS
natiny.backend.NONE "none" Every platform

Returns

Type Description
boolean true on success; false if this build cannot use the requested backend

The engine carries every backend enabled for its platform; this call is the only place the choice is made.

natiny.backend.NONE runs the engine without graphics, for example as a server, tool or test. There is no window: natiny.window.create raises an error. natiny.backend.loop keeps its own time instead of following a display, calling the callback 60 times per second until natiny.backend.stop. Audio, physics, animation, resources and scripts continue to run. natiny.backend.AUTO never selects this backend.

natiny.backend.GLES means OpenGL ES 3.0, called WebGL 2.0 in a browser. The single constant works for both names; natiny.backend.get_name reports the name used on the current platform.

natiny.backend.GLES is the fallback everywhere it exists, but natiny.backend.AUTO selects it automatically only on the web:

Platform natiny.backend.AUTO selects GLES fallback
Web WebGPU when navigator.gpu is available Automatic
Android Vulkan Only when requested explicitly
iOS Metal Only when requested explicitly

Example

Lua
if not natiny.backend.init(natiny.backend.AUTO) then
    os.exit(1)
end

print(natiny.backend.get_name(natiny.backend.get_current()))

-- ... your code ...
natiny.backend.shutdown()

Notes

  • Must be called exactly once at startup.
  • An unavailable backend prints the backends present in this build, returns false, and leaves natiny.window.create unable to create a window.