stb Libraries

repository·master·Indexed 12 days ago

https://github.com/nothings/stb

A collection of single-file, public domain or MIT licensed libraries for C/C++. Provides lightweight solutions for image loading (stb_image.h), font rasterization (stb_truetype.h), audio decoding (stb_vorbis.c), and general utilities like dynamic arrays and hash tables (stb_ds.h).

Tokens
1.2K
Snippets
2
Records
10
Agent score
93%

What's inside stb

  1. Licensing for stb libraries

    master

    The stb libraries are provided in the public domain. You can use them for any purpose without legal obligation, though attribution is appreciated.

    If your legal requirements prefer a standard open-source license, the libraries are also dual-licensed under the MIT license. Every source file contains an explicit dual-license declaration allowing you to choose the one that best fits your needs. Because they are public domain, you can wrap them in a new library and relicense that new library under any license you choose.

  2. How to declare public domain software with a fallback license

    master

    Because 'public domain' declarations are not universally recognized in all jurisdictions (such as the USA), it is recommended to use a dual-license approach to reduce legal friction for users. This involves declaring the software as public domain while providing a fallback clause that grants explicit permissions.

    To implement this, place a declaration at the end of the initial comment block of your file. You can state 'public domain' at the top and use the following fallback text to ensure users have a clear, irrevocable license to use the code.

    // This software is dual-licensed to the public domain and under the following
    // license: you are granted a perpetual, irrevocable license to copy, modify,
    // publish, and distribute this file as you see fit.
  3. How to use stb single-header libraries

    master

    The stb libraries are distributed as single-header files. By default, including the .h file only provides function declarations and does not compile any code.

    To use a library, you must select exactly one C or C++ source file to host the implementation. In that file, you must define a specific implementation macro (provided in the header's documentation) before including the header.

    Example for stb_image.h:

    #define STB_IMAGE_IMPLEMENTATION
    #include "stb_image.h"

    In all other files where you need to use the library, simply include the header without defining the implementation macro:

    #include "stb_image.h"
    #define STB_IMAGE_IMPLEMENTATION
    #include "stb_image.h"
  4. Overview of stb libraries by category

    master
    The stb repository is a collection of single-header C libraries covering various domains including audio, graphics, utilities, and game development. Each library is designed to be easily integrated into projects.
  5. Game development and math utilities with stb

    master

    The following libraries provide specialized game dev and math tools:

    • stb_tilemap_editor.h: An embeddable tilemap editor.
    • stb_herringbone_wang_tile.h: A herringbone Wang tile map generator.
    • stb_divide.h: Provides more useful 32-bit modulus operations, such as "euclidean divide".
  6. Image processing and font handling with stb

    master

    The following libraries provide graphics and font capabilities:

    • stb_image.h: Loads and decodes images from file or memory. Supported formats: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC.
    • stb_image_write.h: Writes images to disk in PNG, TGA, or BMP formats.
    • stb_image_resize2.h: Resizes images (larger or smaller) with high quality.
    • stb_truetype.h: Parses, decodes, and rasterizes characters from TrueType fonts.
    • stb_rect_pack.h: A simple 2D rectangle packer.
    • stb_perlin.h: Implements Perlin's revised simplex noise with different seeds.
    • stb_easy_font.h: Provides a quick-and-dirty bitmap font for simple tasks like printing frame rates.
  7. 3D graphics and voxel rendering with stb

    master

    The following libraries provide 3D graphics capabilities:

    • stb_voxel_render.h: A Minecraft-esque voxel rendering engine with advanced features.
    • stb_dxt.h: A real-time DXT compressor (based on Fabian "ryg" Giesen's implementation).
    • stb_easy_font.h: (Also used for 3D graphics) Quick bitmap font for printing text in 3D environments.
  8. Utilities and parsing with stb

    master

    The following libraries provide general-purpose utilities:

    • stb_ds.h: Provides typesafe dynamic arrays and hash tables for C (also compatible with C++).
    • stb_sprintf.h: Provides fast sprintf and snprintf implementations for C/C++.
    • stb_c_lexer.h: Simplifies the process of writing parsers for C-like languages.
    • stb_include.h: Implements recursive #include support, useful for environments like GLSL.
    • stb_textedit.h: Provides the core logic (guts) for implementing a text editor.