Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (753)
Games in Android Showcase (228)
games submitted by our members
Games in WIP (842)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  LWJGL stb bindings  (Read 23824 times)
0 Members and 2 Guests are viewing this topic.
Offline Spasi
« Posted 2015-05-21 20:32:42 »

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):

STBEasyFont (demo)

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.

STBTruetype (simple demo - advanced demo)

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.

STBRectPack

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.

STBImage (demo)

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)

STBImageResize

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.

STBImageWrite

Simple library for writing image files. Supports:

  • PNG
  • BMP
  • TGA
  • HDR

It is meant for saving screenshots to disk, so it is optimized for encoding speed, not compression ratio.

STBDXT

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.

STBVorbis (demo)

An Ogg Vorbis audio decoder. Seeking is not properly implemented yet, only "rewind" works.

STBPerlin

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.

General notes

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).
Offline NegativeZero

JGO Kernel


Medals: 329
Exp: 1 month or less


Zero but not.


« Reply #1 - Posted 2015-07-01 06:25:25 »

@Spasi, all the Github links from this page are now 404'ing.

Offline Spasi
« Reply #2 - Posted 2015-07-01 08:13:21 »

Thanks, fixed.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ags1

JGO Kernel


Medals: 363
Projects: 7


Make code not war!


« Reply #3 - Posted 2015-07-02 20:20:59 »

Awesome stuff. Much appreciated.

Offline Spasi
« Reply #4 - Posted 2015-07-16 08:33:29 »

The latest nightly build includes an updated font rasterizer, as described here: How the stb_truetype Anti-Aliased Software Rasterizer v2 Works
Offline zeejfps

Senior Newbie


Exp: 2 years



« Reply #5 - Posted 2015-12-27 23:01:16 »

Most of the examples for the TrueType usage seem to be using an outdated API that more closely resembles the C version. Also it uses the fixed pipeline for drawing the quads. Is there better documentation that I can find or better examples?
Offline Spasi
« Reply #6 - Posted 2015-12-28 01:47:25 »

Most of the examples for the TrueType usage seem to be using an outdated API that more closely resembles the C version.

There are functions in stb_truetype that can be used to render text in a few different ways. Which ones you use depends on the level of quality, performance and customization you're interested in. There's no outdated API afaik. The Truetype demo uses the simple stbtt_BakeFontBitmap/stbtt_GetBakedQuad and the TruetypeOversample demo uses the higher quality stbtt_PackFontRanges/stbtt_GetPackedQuad. Neither demo handles codepoint kerning (not all fonts come with kerning information), but it's easy to add.

Also it uses the fixed pipeline for drawing the quads.

The purpose of these demos is to provide sample usage of the stb_truetype API. How to best render the quads is a generic OpenGL question and not specific to font rendering. They're just simple quads with a position and a texcoord. The answer will depend on the application and how much caching (of character sequences) it is able to do.

Is there better documentation that I can find or better examples?

There's plenty of javadoc in the STBTruetype class. Also, reading this will be useful.
Offline zeejfps

Senior Newbie


Exp: 2 years



« Reply #7 - Posted 2015-12-28 07:53:27 »

Thanks for the reply. I realized I am an idiot, my lwjgl wasn't the latest nightly build so the API differed.
Offline DesertCoockie
« Reply #8 - Posted 2018-03-23 19:23:43 »

Links are dead! Please update them, thanks  Wink
Offline Spasi
« Reply #9 - Posted 2018-03-23 19:36:54 »

Thanks, fixed.
Pages: [1]
  ignore  |  Print  
 
 

 
ivj94 (583 views)
2018-03-24 14:47:39

ivj94 (47 views)
2018-03-24 14:46:31

ivj94 (374 views)
2018-03-24 14:43:53

Solater (61 views)
2018-03-17 05:04:08

nelsongames (108 views)
2018-03-05 17:56:34

Gornova (150 views)
2018-03-02 22:15:33

buddyBro (693 views)
2018-02-28 16:59:18

buddyBro (91 views)
2018-02-28 16:45:17

xxMrPHDxx (493 views)
2017-12-31 17:17:51

xxMrPHDxx (732 views)
2017-12-31 17:15:51
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!