Top Description Constructors Methods
org.lwjgl.stb

public Class STBEasyFont

extends Object
Class Inheritance
Imports
javax.annotation.*, java.nio.*, org.lwjgl.system.*

Native bindings to stb_easy_font.h from the stb library.

Bitmap font for use in 3D APIs:

Intended for when you just want to get some text displaying in a 3D app as quickly as possible.

Doesn't use any textures, instead builds characters out of quads.

SAMPLE CODE

Here's sample code for old OpenGL; it's a lot more complicated to make work on modern APIs, and that's your problem.


void print_string(float x, float y, char *text, float r, float g, float b)
{
    static char buffer[99999]; // ~500 chars
    int num_quads;

    num_quads = stb_easy_font_print(x, y, text, NULL, buffer, sizeof(buffer));

    glColor3f(r,g,b);
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_FLOAT, 16, buffer);
    glDrawArrays(GL_QUADS, 0, num_quads*4);
    glDisableClientState(GL_VERTEX_ARRAY);
}

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public static native int
nstb_easy_font_height(long text)

Unsafe version of: easy_font_height

public static native int
nstb_easy_font_print(float x, float y, long text, long color, long vertex_buffer, int
the vertex_buffer size, in bytes
vbuf_size
)

Unsafe version of: easy_font_print

public static native int
nstb_easy_font_width(long text)

Unsafe version of: easy_font_width

public static int

Returns:

the vertical size, in pixels
stb_easy_font_height
(ByteBuffer
an ASCII string
text
)

Takes a string and returns the vertical size (which can vary if text has newlines).

public static int

Returns:

the vertical size, in pixels
stb_easy_font_height
(CharSequence
an ASCII string
text
)

Takes a string and returns the vertical size (which can vary if text has newlines).

public static int

Returns:

the number of quads
stb_easy_font_print
(float
the x offset
x
,
float
the y offset
y
,
ByteBuffer
an ASCII string
text
,
ByteBuffer
the text color, in RGBA (4 bytes)
color
,
ByteBuffer
a pointer to memory in which to store the vertex data
vertex_buffer
)

Takes a string (which can contain '\n') and fills out a vertex buffer with renderable data to draw the string.

public static int

Returns:

the number of quads
stb_easy_font_print
(float
the x offset
x
,
float
the y offset
y
,
CharSequence
an ASCII string
text
,
ByteBuffer
the text color, in RGBA (4 bytes)
color
,
ByteBuffer
a pointer to memory in which to store the vertex data
vertex_buffer
)

Takes a string (which can contain '\n') and fills out a vertex buffer with renderable data to draw the string.

public static native void
stb_easy_font_spacing(float
the font spacing
spacing
)

Use positive values to expand the space between characters, and small negative values (no smaller than -1.5) to contract the space between characters.

public static int

Returns:

the horizontal size, in pixels
stb_easy_font_width
(ByteBuffer
an ASCII string
text
)

Takes a string and returns the horizontal size.

public static int

Returns:

the horizontal size, in pixels
stb_easy_font_width
(CharSequence
an ASCII string
text
)

Takes a string and returns the horizontal size.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

STBEasyFontback to summary
protected STBEasyFont()

Method Detail

nstb_easy_font_heightback to summary
public static native int nstb_easy_font_height(long text)

Unsafe version of: easy_font_height

nstb_easy_font_printback to summary
public static native int nstb_easy_font_print(float x, float y, long text, long color, long vertex_buffer, int vbuf_size)

Unsafe version of: easy_font_print

Parameters
vbuf_size:int

the vertex_buffer size, in bytes

nstb_easy_font_widthback to summary
public static native int nstb_easy_font_width(long text)

Unsafe version of: easy_font_width

stb_easy_font_heightback to summary
public static int stb_easy_font_height(ByteBuffer text)

Takes a string and returns the vertical size (which can vary if text has newlines).

Parameters
text:ByteBuffer

an ASCII string

Returns:int

the vertical size, in pixels

stb_easy_font_heightback to summary
public static int stb_easy_font_height(CharSequence text)

Takes a string and returns the vertical size (which can vary if text has newlines).

Parameters
text:CharSequence

an ASCII string

Returns:int

the vertical size, in pixels

stb_easy_font_printback to summary
public static int stb_easy_font_print(float x, float y, ByteBuffer text, ByteBuffer color, ByteBuffer vertex_buffer)

Takes a string (which can contain '\n') and fills out a vertex buffer with renderable data to draw the string. Output data assumes increasing x is rightwards, increasing y is downwards.

The vertex data is divided into quads, i.e. there are four vertices in the vertex buffer for each quad.

The vertices are stored in an interleaved format:


x:float
y:float
z:float
color:uint8[4]

You can ignore z and color if you get them from elsewhere. This format was chosen in the hopes it would make it easier for you to reuse existing buffer-drawing code.

If you pass in NULL for color, it becomes 255,255,255,255.

If the buffer isn't large enough, it will truncate. Expect it to use an average of ~270 bytes per character.

If your API doesn't draw quads, build a reusable index list that allows you to render quads as indexed triangles.

Parameters
x:float

the x offset

y:float

the y offset

text:ByteBuffer

an ASCII string

color:ByteBuffer

the text color, in RGBA (4 bytes)

vertex_buffer:ByteBuffer

a pointer to memory in which to store the vertex data

Returns:int

the number of quads

stb_easy_font_printback to summary
public static int stb_easy_font_print(float x, float y, CharSequence text, ByteBuffer color, ByteBuffer vertex_buffer)

Takes a string (which can contain '\n') and fills out a vertex buffer with renderable data to draw the string. Output data assumes increasing x is rightwards, increasing y is downwards.

The vertex data is divided into quads, i.e. there are four vertices in the vertex buffer for each quad.

The vertices are stored in an interleaved format:


x:float
y:float
z:float
color:uint8[4]

You can ignore z and color if you get them from elsewhere. This format was chosen in the hopes it would make it easier for you to reuse existing buffer-drawing code.

If you pass in NULL for color, it becomes 255,255,255,255.

If the buffer isn't large enough, it will truncate. Expect it to use an average of ~270 bytes per character.

If your API doesn't draw quads, build a reusable index list that allows you to render quads as indexed triangles.

Parameters
x:float

the x offset

y:float

the y offset

text:CharSequence

an ASCII string

color:ByteBuffer

the text color, in RGBA (4 bytes)

vertex_buffer:ByteBuffer

a pointer to memory in which to store the vertex data

Returns:int

the number of quads

stb_easy_font_spacingback to summary
public static native void stb_easy_font_spacing(float spacing)

Use positive values to expand the space between characters, and small negative values (no smaller than -1.5) to contract the space between characters.

E.g. spacing = 1 adds one "pixel" of spacing between the characters. spacing = -1 is reasonable but feels a bit too compact to me; -0.5 is a reasonable compromise as long as you're scaling the font up.

Parameters
spacing:float

the font spacing

stb_easy_font_widthback to summary
public static int stb_easy_font_width(ByteBuffer text)

Takes a string and returns the horizontal size.

Parameters
text:ByteBuffer

an ASCII string

Returns:int

the horizontal size, in pixels

stb_easy_font_widthback to summary
public static int stb_easy_font_width(CharSequence text)

Takes a string and returns the horizontal size.

Parameters
text:CharSequence

an ASCII string

Returns:int

the horizontal size, in pixels