{"id":13531034,"url":"https://github.com/memononen/fontstash","last_synced_at":"2025-04-04T16:16:29.994Z","repository":{"id":10742994,"uuid":"13000373","full_name":"memononen/fontstash","owner":"memononen","description":"Light-weight online font texture atlas builder","archived":false,"fork":false,"pushed_at":"2023-07-13T19:18:40.000Z","size":1347,"stargazers_count":708,"open_issues_count":16,"forks_count":89,"subscribers_count":43,"default_branch":"master","last_synced_at":"2025-03-28T15:09:34.881Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"eligrey/jsandbox","license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/memononen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2013-09-21T18:49:59.000Z","updated_at":"2025-03-26T09:53:14.000Z","dependencies_parsed_at":"2024-01-03T04:00:35.783Z","dependency_job_id":"ef872b3d-7331-47c2-96ed-b390781d95bd","html_url":"https://github.com/memononen/fontstash","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/memononen%2Ffontstash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/memononen%2Ffontstash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/memononen%2Ffontstash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/memononen%2Ffontstash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/memononen","download_url":"https://codeload.github.com/memononen/fontstash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247208183,"owners_count":20901570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T07:00:59.238Z","updated_at":"2025-04-04T16:16:29.973Z","avatar_url":"https://github.com/memononen.png","language":"C","readme":"*This project is not actively maintained.*\n\nFont Stash\n==========\n\nFont stash is light-weight online font texture atlas builder written in C. It uses [stb_truetype](http://nothings.org) to render fonts on demand to a texture atlas.\n\nThe code is split in two parts, the font atlas and glyph quad generator [fontstash.h](/src/fontstash.h), and an example OpenGL backend ([glstash.h](/glstash.h).\n\n## Screenshot\n\n![screenshot of some text rendered witht the sample program](/screenshots/screen-01.png?raw=true)\n\n## Example\n``` C\n// Create GL stash for 512x512 texture, our coordinate system has zero at top-left.\nstruct FONScontext* fs = glfonsCreate(512, 512, FONS_ZERO_TOPLEFT);\n\n// Add font to stash.\nint fontNormal = fonsAddFont(fs, \"sans\", \"DroidSerif-Regular.ttf\");\n\n// Render some text\nfloat dx = 10, dy = 10;\nunsigned int white = glfonsRGBA(255,255,255,255);\nunsigned int brown = glfonsRGBA(192,128,0,128);\n\nfonsSetFont(fs, fontNormal);\nfonsSetSize(fs, 124.0f);\nfonsSetColor(fs, white);\nfonsDrawText(fs, dx,dy,\"The big \", NULL);\n\nfonsSetSize(fs, 24.0f);\nfonsSetColor(fs, brown);\nfonsDrawText(fs, dx,dy,\"brown fox\", NULL);\n```\n\n## Using Font Stash in your project\n\nIn order to use fontstash in your own project, just copy fontstash.h, stb_truetype.h, and potentially glstash.h to your project.\nIn one C/C++ define FONTSTASH_IMPLEMENTATION before including the library to expand the font stash implementation in that file.\n\n``` C\n#include \u003cstdio.h\u003e\t\t\t\t\t// malloc, free, fopen, fclose, ftell, fseek, fread\n#include \u003cstring.h\u003e\t\t\t\t\t// memset\n#define FONTSTASH_IMPLEMENTATION\t// Expands implementation\n#include \"fontstash.h\"\n```\n\n``` C\n#include \u003cGLFW/glfw3.h\u003e\t\t\t\t// Or any other GL header of your choice.\n#define GLFONTSTASH_IMPLEMENTATION\t// Expands implementation\n#include \"glfontstash.h\"\n```\n\n## Creating new rendering backend\n\nThe default rendering backend uses OpenGL to render the glyphs. If you want to render the text using some other API, or want tighter integration with your code base you can write your own rendering backend. Take a look at the [glfontstash.h](/src/glfontstash.h) for reference implementation.\n\nThe rendering interface FontStash assumes access to is defined in the FONSparams structure. The renderer initialization function is assumed to fill in the FONSparams structure and call fonsCreateInternal to create the FontStash context.\n\n```C\nstruct FONSparams {\n\t...\n\tvoid* userPtr;\n\tint (*renderCreate)(void* uptr, int width, int height);\n\tint (*renderResize)(void* uptr, int width, int height);\n\tvoid (*renderUpdate)(void* uptr, int* rect, const unsigned char* data);\n\tvoid (*renderDraw)(void* uptr, const float* verts, const float* tcoords, const unsigned int* colors, int nverts);\n\tvoid (*renderDelete)(void* uptr);\n};\n```\n\n- **renderCreate** is called to create renderer for specific API, this is where you should create a texture of given size.\n\t- return 1 of success, or 0 on failure.\n- **renderResize** is called to resize the texture. Called when user explicitly expands or resets the atlas texture.\n\t- return 1 of success, or 0 on failure.\n- **renderUpdate** is called to update texture data\n\t- _rect_ describes the region of the texture that has changed\n\t- _data_ pointer to full texture data\n- **renderDraw** is called when the font triangles should be drawn\n\t- _verts_ pointer to vertex position data, 2 floats per vertex\n\t- _tcoords_ pointer to texture coordinate data, 2 floats per vertex\n\t- _colors_ pointer to color data, 1 uint per vertex (or 4 bytes)\n\t- _nverts_ is the number of vertices to draw\n- **renderDelete** is called when the renderer should be deleted\n- **userPtr** is passed to all calls as first parameter\n\nFontStash uses this API as follows:\n\n```\nfonsDrawText() {\n\tforeach (glyph in input string) {\n\t\tif (internal buffer full) {\n\t\t\tupdateTexture()\n\t\t\trender()\n\t\t}\n\t\tadd glyph to interal draw buffer\n\t}\n\tupdateTexture()\n\trender()\n}\n```\n\nThe size of the internal buffer is defined using `FONS_VERTEX_COUNT` define. The default value is 1024, you can override it when you include fontstash.h and specify the implementation:\n\n``` C\n#define FONS_VERTEX_COUNT 2048\n#define FONTSTASH_IMPLEMENTATION\t// Expands implementation\n#include \"fontstash.h\"\n```\n\n## Compiling\n\nIn order to compile the demo project, your will need to install [GLFW](http://www.glfw.org/) to compile.\n\nFontStash example project uses [premake4](http://industriousone.com/premake) to build platform specific projects, now is good time to install it if you don't have it already. To build the example, navigate into the root folder in your favorite terminal, then:\n\n- *OS X*: `premake4 xcode4`\n- *Windows*: `premake4 vs2010`\n- *Linux*: `premake4 gmake`\n\nSee premake4 documentation for full list of supported build file types. The projects will be created in `build` folder. An example of building and running the example on OS X:\n\n```bash\n$ premake4 gmake\n$ cd build/\n$ make\n$ ./example\n```\n\n# License\nThe library is licensed under [zlib license](LICENSE.txt)\n\n## Links\nUses [stb_truetype](http://nothings.org) for font rendering.\n","funding_links":[],"categories":["Libraries"],"sub_categories":["C"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmemononen%2Ffontstash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmemononen%2Ffontstash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmemononen%2Ffontstash/lists"}