jkuhlmann/cgltf logo

jkuhlmann/cgltf

Free

:diamond_shape_with_a_dot_inside: Single-file glTF 2.0 loader and writer written in C99

FreeFree tier
Type
Open Source

About jkuhlmann/cgltf

cgltf is a single-file, stb-style C99 library for loading and writing glTF 2.0 files. It supports both glTF (JSON) and glb (binary) formats, including meshes, accessors, buffer views, buffers, materials, textures, samplers, images, scenes, nodes, skins, animations, cameras, morph targets, and extras data. The library also supports several glTF extensions such as EXT_mesh_gpu_instancing, EXT_meshopt_compression, EXT_texture_webp, and KHR_draco_mesh_compression (requires an external library). It is used in popular projects like bgfx, Filament, gltfpack, raylib, and Unigine. Loading can be done from file or memory, and writing is similarly supported. cgltf does not automatically load external buffer or image files; users must handle those or call cgltf_load_buffers for buffer data. The writer does not output external buffer or image data either.

Key Features

Single-file, stb-style integration, requiring only one .h file
Supports both glTF (JSON) and glb (binary) file formats
Core glTF 2.0 support: meshes, materials, scenes, nodes, skins, animations, cameras, morph targets, extras
Extension support: EXT_mesh_gpu_instancing, EXT_meshopt_compression, EXT_texture_webp, KHR_draco_mesh_compression
Loading from file or memory
Writing to file or memory
cgltf_load_buffers helper to open and read buffer files (including base64 data URIs)
Used in major open-source projects like bgfx, Filament, gltfpack, raylib, Unigine

Pros & Cons

Pros
  • Single-file header – easy to drop into any C/C++ project
  • Supports a wide range of core glTF 2.0 features and popular extensions
  • Lightweight and minimal dependencies (standard C library only)
  • Proven in production by several well-known projects
  • Both loading and writing are provided in a consistent API
Cons
  • Does not automatically load external buffer or image files; user must handle file I/O or use helper functions
  • Writer does not output external buffer or image data either
  • Draco mesh compression support requires an external library
  • Only supports glTF 2.0; no support for older glTF versions

Best For

Loading glTF 2.0 3D models into game engines or rendering applicationsWriting glTF 2.0 assets programmaticallyIntegrating glTF support into C/C++ tools and pipelinesEducation and prototyping with minimal dependencies

FAQ

What glTF extensions does cgltf support?
cgltf supports EXT_mesh_gpu_instancing, EXT_meshopt_compression, EXT_texture_webp, and KHR_draco_mesh_compression (the latter requires an external library).
Does cgltf automatically load buffer and image files?
No. By default cgltf only parses the glTF descriptor. You must load buffer and image files yourself using URIs from data.buffers[] or data.images[]. Alternatively, cgltf_load_buffers can open and read buffer files via FILE* APIs, and cgltf_load_buffer_base64 can decode base64 data URIs in images.
Is cgltf used in any well-known projects?
Yes, cgltf is used in bgfx, Filament, gltfpack, raylib, and Unigine, among others.