macOS
Download the SDK bundle - arm64 for Apple silicon, amd64 for an Intel
Mac - and put main.c beside the folders it unzipped:
my_game/
├── include/
│ └── natiny.h
├── lib/
│ └── libnatiny_macos_arm64.a
└── main.c
#include "natiny.h"
#include <stddef.h>
static NatinyWindow window;
static void frame(float dt, void* userdata)
{
(void)dt;
(void)userdata;
natiny_window_bind(window);
natiny_render_clear(0.07f, 0.09f, 0.13f, 1.0f);
natiny_render_set_color(0.66f, 0.76f, 0.22f, 1.0f);
natiny_render_rectangle(360.0f, 260.0f, 80.0f, 80.0f);
natiny_window_unbind();
}
int main(void)
{
if (!natiny_backend_init(NATINY_BACKEND_AUTO)) {
return 1;
}
window = natiny_window_create("Hello, Natiny", 800, 600);
if (!window) {
natiny_backend_shutdown();
return 1;
}
natiny_backend_loop(frame, NULL);
natiny_backend_shutdown();
return 0;
}
Compile and link:
clang -O2 -Iinclude -c main.c -o main.o
clang -O2 main.o lib/libnatiny_macos_arm64.a -o app \
-framework Cocoa -framework IOKit -framework CoreFoundation \
-framework CoreVideo -framework Metal -framework QuartzCore \
-lpthread -lm
./app
A dark window opens with a green square in it. Use
libnatiny_macos_amd64.a on an Intel Mac; the frameworks are the same.
libnatiny_macos_arm64.a is the whole engine - GLFW, the shader compiler, the
mixer and the physics solver are already inside it, so there is nothing else of
Natiny's to link. It is plain C with no C++ runtime anywhere, so a C compiler
is all you need. Every framework on that line ships with macOS.
Metal and only Metal. OpenGL on macOS stopped at 4.1 and has been
deprecated since 10.14, and Vulkan there is MoltenVK, which is Metal
underneath - so NATINY_BACKEND_AUTO picks Metal and there is nothing else to
pick. Shaders are compiled to MSL and handed to the driver as source when the
program starts, so a machine running your game needs no part of Xcode.
The SDK README in the bundle also covers linking
libnatiny_macos_arm64.dylib instead of the archive.