natiny.backend.init
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.
backend is one of the constants below, the same thing spelled out as a
string, or nothing at all - which means AUTO. It returns true when the
engine can run what was asked for, and false, after printing what this build
does have, when it cannot.
| 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 |
natiny.backend.WEBGPU |
"webgpu" |
web |
One executable carries every backend its platform can run, so this is the only place the choice is made.
Example
if not natiny.backend.init(natiny.backend.AUTO) then
os.exit(1)
end
local backend = natiny.backend.get_current()
print(natiny.backend.get_name(backend))
-- ... your code ...
natiny.backend.shutdown()
Notes
- Must be called exactly once at startup.
- Asking for a backend this platform does not carry is not fatal by itself -
it returns
false, andnatiny.window.createthen fails too.