natiny_backend_init

C
int natiny_backend_init(int backend);

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

Parameters

Name Type Description
backend int Backend constant below

Constants

Constant Platforms
NATINY_BACKEND_AUTO The platform's first choice
NATINY_BACKEND_D3D12 Windows
NATINY_BACKEND_VULKAN Windows, Linux
NATINY_BACKEND_OPENGL Windows, Linux
NATINY_BACKEND_METAL macOS, iOS
NATINY_BACKEND_WEBGPU Web
NATINY_BACKEND_GLES Web, Android, iOS
NATINY_BACKEND_NONE Every platform

Returns

Type Description
int Non-zero on success; 0 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 returns 0. 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.

For Native programs, linking also follows use: code that calls no natiny_window_* function links no window, GPU device, GLFW or graphics backend from the static library. NATINY_BACKEND_NONE still provides the engine loop in that configuration.

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

C
int main(void) {
    if (!natiny_backend_init(NATINY_BACKEND_AUTO))
        return 1;

    printf("%s\n", natiny_backend_get_name(natiny_backend_get_current()));

    // ... your code ...
    natiny_backend_shutdown();
    return 0;
}

Notes

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