Giter VIP home page Giter VIP logo

fontstash's Introduction

Font Stash: Dynamic font glyph cache for OpenGL

Font Stash enables easy string rendering in OpenGL applications. It supports truetype fonts and UTF-8 encoded localized strings. All glyphs are cached in OpenGL texture atlases. Font rasterization is done using Sean Barrett's stb_truetype.h.

Font Stash was originally created and published by Mikko Mononen.

Major changes to the original version

  • Bitmap font support
  • Truetype font loading from memory
  • Added ability to load an arbitrary number of fonts (not just four)
  • Use multiple OpenGL textures for glyph caching (not just one)

Screenshot

Screenshot

Usage

If you're using OpenGL 3 (no immediate mode), leave the STH_OPENGL3 macro defined on fontstash.h. If you're using immediate mode, comment the line and you're fine.

#include "fontstash.h"

...
/* create a font stash with a maximum texture size of 512 x 512 */
struct sth_stash* stash = sth_create(512, 512);
/* load truetype font */
int droid = sth_add_font(stash, "DroidSerif-Regular.ttf");
/* position of the text */
float x = 10, y = 10;
...
/* draw text during your OpenGL render loop */
sth_begin_draw(stash);
/* position: (x, y); font size: 24 */
sth_draw_text(stash, droid, 24.0f, x, y, "Hello world!", &x);
/* now, the float x contains the x position of the next char */
sth_end_draw(stash);
... 

Bitmap fonts

Bitmap fonts can be generated using the AngelCode Bitmap Font Generator. It's a Windows program that runs under Linux using Wine. This program generates one or more image files and a text file (*.fnt) containing the bounding box coordinates of all individual glyphs. These coordinates are used to reference the glyphs using Font Stash.

License

The files fontstash.c, fontstash.h, fragmentShader.h and vertexShader.h are licensed under the zlib license:

Copyright (c) 2014 Sergio Moura [email protected]
Copyright (c) 2011-2013 Andreas Krinke [email protected]
Copyright (c) 2009 Mikko Mononen [email protected]

This software is provided 'as-is', without any express or implied
warranty.  In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
   claim that you wrote the original software. If you use this software
   in a product, an acknowledgment in the product documentation would be
   appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
   misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

For UTF-8 decoding, Font Stash uses Björn Höhrmann's Flexible and Economical UTF-8 Decoder (included in fontstash.c). His code is licensed under the MIT license:

Copyright (c) 2008-2009 Bjoern Hoehrmann <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE SOFTWARE.

Finally, Font Stash uses Sean Barrett's public domain truetype font rasterizer stb_truetype.h.

fontstash's People

Contributors

akrinke avatar lsmoura avatar sjml avatar

Stargazers

 avatar  avatar Jacob Paul Adkins avatar  avatar  avatar Jan Staubach avatar chu avatar Victor Zverovich avatar Ryan Showalter avatar Chris avatar Johan Berg avatar Donal Mac Carthy avatar AJ Kelly avatar Jonathan Payne avatar Nik Voss avatar Brian Racer avatar Pol Gómez Riquelme avatar Kristoffer Grönlund avatar Richard Palm avatar

Watchers

 avatar James Cloos avatar

Forkers

nyorem

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.