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.
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);
}
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public static native int | |
| public static native int | nstb_easy_font_print(float x, float y, long text, long color, long vertex_buffer, int
the vbuf_size)vertex_buffer size, in bytesUnsafe version of: |
| public static native int | |
| public static int | Returns: the vertical size, in pixelsan ASCII string text)Takes a string and returns the vertical size (which can vary if |
| public static int | Returns: the vertical size, in pixelsan ASCII string text)Takes a string and returns the vertical size (which can vary if |
| public static int | Returns: the number of quadsthe 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 quadsthe 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 |
| public static int | Returns: the horizontal size, in pixelsan ASCII string text)Takes a string and returns the horizontal size. |
| public static int | Returns: the horizontal size, in pixelsan ASCII string text)Takes a string and returns the horizontal size. |
| STBEasyFont | back to summary |
|---|---|
| protected STBEasyFont() | |
| nstb_easy_font_height | back to summary |
|---|---|
| public static native int nstb_easy_font_height(long text) Unsafe version of: | |
| nstb_easy_font_print | back 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:
| |
| nstb_easy_font_width | back to summary |
|---|---|
| public static native int nstb_easy_font_width(long text) Unsafe version of: | |
| stb_easy_font_height | back to summary |
|---|---|
| public static int stb_easy_font_height(ByteBuffer text) Takes a string and returns the vertical size (which can vary if
| |
| stb_easy_font_height | back to summary |
|---|---|
| public static int stb_easy_font_height(CharSequence text) Takes a string and returns the vertical size (which can vary if
| |
| stb_easy_font_print | back 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:
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 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.
| |
| stb_easy_font_print | back 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:
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 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.
| |
| stb_easy_font_spacing | back 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 E.g.
| |
| stb_easy_font_width | back to summary |
|---|---|
| public static int stb_easy_font_width(ByteBuffer text) Takes a string and returns the horizontal size.
| |
| stb_easy_font_width | back to summary |
|---|---|
| public static int stb_easy_font_width(CharSequence text) Takes a string and returns the horizontal size.
| |