Configs2026年5月26日·1 分钟阅读

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.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
stb Overview
直接安装命令
npx -y tokrepo@latest install 34a88962-5898-11f1-9bc6-00163e2b0d79 --target codex

先 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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产