The latest LWJGL 3 nightly build (#49) now features bindings to the stb collection of “single-file public domain libraries for C/C++”. Not everything is supported, only libraries that make sense in Java and are lightweight enough for LWJGL.
The main motivation for adding these bindings was to allow LWJGL users to get rid of any dependencies to AWT (e.g. for loading fonts or images). There are many other options of course, but stb is a solution that was very easy to support and should cover most needs. It is developed by Sean Barrett (works at RAD Game Tools), written in pure C, with functionality focused on game development.
LWJGL includes the following bindings (under the org.lwjgl.stb package):
A quick-and-dirty solution for getting some text rendered in the simplest possible way. It provides a function that converts an ASCII string to an array of GL_QUADS, which you can then render any way you like. It's essentially a monospaced bitmap font.
It’s obviously very inefficient, but you can cache the generated geometry.
Parses .ttf files, returns font/glyph metrics and rasterizes fonts to packed textures.
The API is simple, but this is an advanced library; line metrics, glyph metrics, kerning, pixel snapping, oversampling for small test sizes, subpixel positioning, everything you need is here. Make sure to read this guide on oversampling. The “advanced demo” above is an LWJGL port of the “oversample” test in the stb repository.
Can be used to pack rectangular textures into an atlas. It implements the Skyline Bottom-Left algorithm and is used internally by STBTruetype for the glyph packing.
An image loading library. Supports the following image file formats:
- JPEG baseline & progressive (12 bpc/arithmetic not supported, same as stock IJG lib)
- PNG 1/2/4/8/16-bit-per-channel
- TGA (not sure what subset, if a subset)
- BMP non-1bpp, non-RLE
- PSD (composited view only, no extra channels, 8/16 bit-per-channel)
- GIF (*desired_channels always reports as 4-channel)
- HDR (radiance rgbE format)
- PIC (Softimage PIC)
- PNM (PPM and PGM binary only)
High-quality image resizing. It's sRGB-aware, alpha-aware, supports different edge wrap modes and a variety of filters (including cubic and Mitchell-Netrevalli).
If you’re using glGenerateMipmap or aren’t doing gamma correct mipmap generation, you really really want to use this.
Simple library for writing image files. Supports:
It is meant for saving screenshots to disk, so it is optimized for encoding speed, not compression ratio.
A real-time DXT1/DXT5 compressor. If you need to compress textures at runtime, this should provide better quality than the compression done by OpenGL drivers.
An Ogg Vorbis audio decoder. Seeking is not properly implemented yet, only "rewind" works.
Computes Perlin's revised noise function (3D input, 1D output). I'm not sure how this performs in terms of speed and quality; if anyone tests it, please post here.
Try to avoid the "filename" APIs (in STBImage, STBImageWrite and STBVorbis), they do not support unicode paths atm (on Windows). Better use standard Java IO to load the files in memory and use the corresponding APIs.
I haven’t had the time to test everything, let me know if you encounter any issues. You can see a video of some of the above here (GIF, 7.43 MB).