recp/cglm logo

recp/cglm

Free

📽 Highly Optimized 2D / 3D Graphics Math (glm) for C

FreeFree tier
Type
Open Source

About recp/cglm

cglm is a highly optimized 2D and 3D graphics math library for C, also known as OpenGL Mathematics (glm) for C. It provides fast and ergonomic math functions designed to ease graphics programming. The library is allocation-free, header-only (optional linking), SIMD-optimized, and API-agnostic. It supports multiple usage styles: header-only with glm_ prefix, struct API with glms_ prefix, and linked API with glmc_ prefix. cglm is community-friendly, well-documented, and compatible with various build systems (CMake, Meson, Autotools, etc.).

Key Features

Allocation-free library with optional header-only usage
SIMD-optimized for performance on modern CPUs
API-agnostic: supports header-only, struct, and linked APIs
Comprehensive documentation in headers and online
Supports multiple build systems: CMake, Meson, Autotools, Makefile.am
Struct API allows const variables and return-by-value
Alignment control via CGLM_ALL_UNALIGNED define

Pros & Cons

Pros
  • Highly optimized with SIMD support for fast math operations
  • Flexible usage: header-only or linked, struct or traditional API
  • Free and open source with permissive MIT license
  • Thoroughly documented with examples in headers and online
  • Lightweight and allocation-free, suitable for performance-critical code
Cons
  • Requires careful data alignment for full SIMD benefits; unaligned versions available but slower
  • C-only library; C++ users may prefer GLM directly
  • Manual memory management may be needed when not using header-only mode
  • Documentation relies on header comments; separate documentation site may be less comprehensive

Best For

Graphics programming and game development3D rendering and GPU compute applicationsScientific visualization and simulationEducational projects for learning linear algebraEmbedded systems with resource constraints (allocation-free)

FAQ

What is cglm?
cglm is a highly optimized 2D/3D graphics math library for C, also known as OpenGL Mathematics (glm) for C. It provides fast and ergonomic math functions for graphics programming.
How do I use cglm as a header-only library?
Simply include 'cglm/cglm.h' and use functions with the glm_ prefix (e.g., glm_vec2_zero). No linking required.
Does cglm support SIMD instructions?
Yes, cglm is SIMD-optimized. However, you must ensure that arguments like vec4, mat4, and mat2 are properly aligned to avoid crashes on SIMD-capable machines.
What is the struct API in cglm?
The struct API uses types with an 's' suffix (e.g., mat4s) and functions prefixed with glms_. They take parameters by copy and return values directly, allowing const variables and more idiomatic C code.