Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsMay 26, 2026·3 min de lecture

stb — Single-Header C Libraries for Graphics, Audio and More

A collection of public-domain single-file C libraries by Sean Barrett covering image loading, font rendering, noise generation, and more.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
stb Overview
Commande d'installation directe
npx -y tokrepo@latest install 34a88962-5898-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

stb is a collection of about 20 single-file, public-domain C libraries created by Sean Barrett. Each header is entirely self-contained: drop it into your project, define one implementation macro in a single translation unit, and you are done. No build system, no dependencies, no license headaches.

What stb Does

  • Loads and writes PNG, JPEG, BMP, TGA, HDR, and PSD images (stb_image / stb_image_write)
  • Rasterizes TrueType fonts to bitmaps with optional SDF output (stb_truetype)
  • Generates Perlin noise and cellular noise (stb_perlin)
  • Provides a stretchy-buffer (dynamic array) for plain C (stb_ds)
  • Implements Vorbis audio decoding and DXT texture compression

Architecture Overview

Each library is a single .h file that acts as both interface and implementation. When you #define STB_*_IMPLEMENTATION before including it, the compiler emits the function bodies. Without the define, you get declarations only. This approach eliminates build-system coupling and keeps the libraries trivially embeddable in any C or C++ project.

Self-Hosting & Configuration

  • No installation needed — copy the headers you need into your source tree
  • Public domain (or MIT licensed, your choice) so no attribution is required
  • Configure via preprocessor defines before the include (e.g., STBI_NO_JPEG to strip JPEG support)
  • Works with any C89+ or C++ compiler on any platform
  • Compile the implementation in exactly one translation unit to avoid duplicate symbols

Key Features

  • Zero external dependencies for every library in the collection
  • Battle-tested in thousands of commercial games and applications
  • Tiny code size suitable for embedded and WASM targets
  • Each library is independent — use only what you need
  • Actively maintained with contributions from the community

Comparison with Similar Tools

  • lodepng — PNG-only; stb_image handles multiple formats in one header
  • FreeType — full-featured font engine but much larger and harder to integrate
  • libjpeg / libpng — system libraries requiring separate build and linking
  • sokol — similar single-header philosophy but focused on cross-platform graphics APIs
  • dr_libs — single-file audio decoders (WAV, MP3, FLAC) that complement stb

FAQ

Q: Why single-header instead of a proper library? A: Single headers eliminate build-system friction. You can integrate stb into any project in seconds without CMake, Meson, or pkg-config.

Q: Is stb_image production quality? A: Yes. It is used in major game engines, Raylib, Dear ImGui backends, and many AAA studios. It has been fuzzed extensively.

Q: Can I use stb in C++ projects? A: Absolutely. The headers compile cleanly as C++ and are regularly tested with GCC, Clang, and MSVC in both C and C++ modes.

Q: What is the license? A: Dual-licensed as public domain (Unlicense) and MIT. Choose whichever works for your legal requirements.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires