Lines Matching refs:atlas

104 /// NK_INCLUDE_DEFAULT_FONT         | Defining this adds the default font: ProggyClean.ttf into this library which can be loaded into a font atlas and allows using this library without having a truetype font
3754 different ways to use the font atlas. The first two will use your font
3791 `nk_user_font`. First a texture atlas handle used to draw text as subimages
3792 of a bigger font atlas texture and a callback to query a character's glyph
3830 The font baker APIs can be used to create a font plus font atlas texture
3848 inside the font atlas and allows to reuse the font atlas. If you don't want to reuse
3857 will free all temporary memory including the font atlas image so make sure
3863 At this point you are done and if you don't want to reuse the font atlas you
3865 memory. Finally if you don't use the font atlas and any of it's fonts anymore
3868 struct nk_font_atlas atlas;
3869 nk_font_atlas_init_default(&atlas);
3870 nk_font_atlas_begin(&atlas);
3871 nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, 0);
3872 nk_font *font2 = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font2.ttf", 16, 0);
3873 const void* img = nk_font_atlas_bake(&atlas, &img_width, &img_height, NK_FONT_ATLAS_RGBA32);
3874 nk_font_atlas_end(&atlas, nk_handle_id(texture), 0);
3881 nk_font_atlas_clear(&atlas);
3885 to use the font atlas. There are a number of details I left out. For example
3893 nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, &cfg);
3926 /* texture handle to the used font atlas or texture */
3961 /* used inside font atlas: default to: 0*/
3979 /* font to setup in the baking process: NOTE: not needed for font atlas */
4046 NK_API struct nk_font* nk_font_atlas_add_from_memory(struct nk_font_atlas *atlas, void *memory, nk_size size, float height, const struct nk_font_config *config);
4048 NK_API struct nk_font* nk_font_atlas_add_from_file(struct nk_font_atlas *atlas, const char *file_path, float height, const struct nk_font_config*);
4055 NK_API void nk_font_atlas_cleanup(struct nk_font_atlas *atlas);
13097 const struct nk_baked_font *baked_font, nk_handle atlas)
13111 font->texture = atlas;
13442 nk_font_atlas_init_default(struct nk_font_atlas *atlas)
13444 NK_ASSERT(atlas);
13445 if (!atlas) return;
13446 nk_zero_struct(*atlas);
13447 atlas->temporary.userdata.ptr = 0;
13448 atlas->temporary.alloc = nk_malloc;
13449 atlas->temporary.free = nk_mfree;
13450 atlas->permanent.userdata.ptr = 0;
13451 atlas->permanent.alloc = nk_malloc;
13452 atlas->permanent.free = nk_mfree;
13456 nk_font_atlas_init(struct nk_font_atlas *atlas, struct nk_allocator *alloc)
13458 NK_ASSERT(atlas);
13460 if (!atlas || !alloc) return;
13461 nk_zero_struct(*atlas);
13462 atlas->permanent = *alloc;
13463 atlas->temporary = *alloc;
13466 nk_font_atlas_init_custom(struct nk_font_atlas *atlas,
13469 NK_ASSERT(atlas);
13472 if (!atlas || !permanent || !temporary) return;
13473 nk_zero_struct(*atlas);
13474 atlas->permanent = *permanent;
13475 atlas->temporary = *temporary;
13478 nk_font_atlas_begin(struct nk_font_atlas *atlas)
13480 NK_ASSERT(atlas);
13481 NK_ASSERT(atlas->temporary.alloc && atlas->temporary.free);
13482 NK_ASSERT(atlas->permanent.alloc && atlas->permanent.free);
13483 if (!atlas || !atlas->permanent.alloc || !atlas->permanent.free ||
13484 !atlas->temporary.alloc || !atlas->temporary.free) return;
13485 if (atlas->glyphs) {
13486 atlas->permanent.free(atlas->permanent.userdata, atlas->glyphs);
13487 atlas->glyphs = 0;
13489 if (atlas->pixel) {
13490 atlas->permanent.free(atlas->permanent.userdata, atlas->pixel);
13491 atlas->pixel = 0;
13495 nk_font_atlas_add(struct nk_font_atlas *atlas, const struct nk_font_config *config)
13500 NK_ASSERT(atlas);
13501 NK_ASSERT(atlas->permanent.alloc);
13502 NK_ASSERT(atlas->permanent.free);
13503 NK_ASSERT(atlas->temporary.alloc);
13504 NK_ASSERT(atlas->temporary.free);
13511 if (!atlas || !config || !config->ttf_blob || !config->ttf_size || config->size <= 0.0f||
13512 !atlas->permanent.alloc || !atlas->permanent.free ||
13513 !atlas->temporary.alloc || !atlas->temporary.free)
13518 atlas->permanent.alloc(atlas->permanent.userdata,0, sizeof(struct nk_font_config));
13525 if (!atlas->config) {
13526 atlas->config = cfg;
13529 struct nk_font_config *i = atlas->config;
13536 atlas->permanent.alloc(atlas->permanent.userdata,0, sizeof(struct nk_font));
13543 if (!atlas->fonts) {
13544 atlas->fonts = font;
13547 struct nk_font *i = atlas->fonts;
13557 NK_ASSERT(atlas->font_num);
13558 f = atlas->fonts;
13569 cfg->ttf_blob = atlas->permanent.alloc(atlas->permanent.userdata,0, cfg->ttf_size);
13572 atlas->font_num++;
13578 atlas->font_num++;
13582 nk_font_atlas_add_from_memory(struct nk_font_atlas *atlas, void *memory,
13589 NK_ASSERT(atlas);
13590 NK_ASSERT(atlas->temporary.alloc);
13591 NK_ASSERT(atlas->temporary.free);
13592 NK_ASSERT(atlas->permanent.alloc);
13593 NK_ASSERT(atlas->permanent.free);
13594 if (!atlas || !atlas->temporary.alloc || !atlas->temporary.free || !memory || !size ||
13595 !atlas->permanent.alloc || !atlas->permanent.free)
13603 return nk_font_atlas_add(atlas, &cfg);
13607 nk_font_atlas_add_from_file(struct nk_font_atlas *atlas, const char *file_path,
13614 NK_ASSERT(atlas);
13615 NK_ASSERT(atlas->temporary.alloc);
13616 NK_ASSERT(atlas->temporary.free);
13617 NK_ASSERT(atlas->permanent.alloc);
13618 NK_ASSERT(atlas->permanent.free);
13620 if (!atlas || !file_path) return 0;
13621 memory = nk_file_load(file_path, &size, &atlas->permanent);
13629 return nk_font_atlas_add(atlas, &cfg);
13633 nk_font_atlas_add_compressed(struct nk_font_atlas *atlas,
13641 NK_ASSERT(atlas);
13642 NK_ASSERT(atlas->temporary.alloc);
13643 NK_ASSERT(atlas->temporary.free);
13644 NK_ASSERT(atlas->permanent.alloc);
13645 NK_ASSERT(atlas->permanent.free);
13649 if (!atlas || !compressed_data || !atlas->temporary.alloc || !atlas->temporary.free ||
13650 !atlas->permanent.alloc || !atlas->permanent.free)
13654 decompressed_data = atlas->permanent.alloc(atlas->permanent.userdata,0,decompressed_size);
13665 return nk_font_atlas_add(atlas, &cfg);
13668 nk_font_atlas_add_compressed_base85(struct nk_font_atlas *atlas,
13675 NK_ASSERT(atlas);
13676 NK_ASSERT(atlas->temporary.alloc);
13677 NK_ASSERT(atlas->temporary.free);
13678 NK_ASSERT(atlas->permanent.alloc);
13679 NK_ASSERT(atlas->permanent.free);
13682 if (!atlas || !data_base85 || !atlas->temporary.alloc || !atlas->temporary.free ||
13683 !atlas->permanent.alloc || !atlas->permanent.free)
13687 compressed_data = atlas->temporary.alloc(atlas->temporary.userdata,0, (nk_size)compressed_size);
13691 font = nk_font_atlas_add_compressed(atlas, compressed_data,
13693 atlas->temporary.free(atlas->temporary.userdata, compressed_data);
13699 nk_font_atlas_add_default(struct nk_font_atlas *atlas,
13702 NK_ASSERT(atlas);
13703 NK_ASSERT(atlas->temporary.alloc);
13704 NK_ASSERT(atlas->temporary.free);
13705 NK_ASSERT(atlas->permanent.alloc);
13706 NK_ASSERT(atlas->permanent.free);
13707 return nk_font_atlas_add_compressed_base85(atlas,
13712 nk_font_atlas_bake(struct nk_font_atlas *atlas, int *width, int *height,
13721 NK_ASSERT(atlas);
13722 NK_ASSERT(atlas->temporary.alloc);
13723 NK_ASSERT(atlas->temporary.free);
13724 NK_ASSERT(atlas->permanent.alloc);
13725 NK_ASSERT(atlas->permanent.free);
13729 if (!atlas || !width || !height ||
13730 !atlas->temporary.alloc || !atlas->temporary.free ||
13731 !atlas->permanent.alloc || !atlas->permanent.free)
13736 if (!atlas->font_num)
13737 atlas->default_font = nk_font_atlas_add_default(atlas, 13.0f, 0);
13739 NK_ASSERT(atlas->font_num);
13740 if (!atlas->font_num) return 0;
13743 nk_font_baker_memory(&tmp_size, &atlas->glyph_count, atlas->config, atlas->font_num);
13744 tmp = atlas->temporary.alloc(atlas->temporary.userdata,0, tmp_size);
13749 baker = nk_font_baker(tmp, atlas->glyph_count, atlas->font_num, &atlas->temporary);
13750 atlas->glyphs = (struct nk_font_glyph*)atlas->permanent.alloc(
13751 atlas->permanent.userdata,0, sizeof(struct nk_font_glyph)*(nk_size)atlas->glyph_count);
13752 NK_ASSERT(atlas->glyphs);
13753 if (!atlas->glyphs)
13757 atlas->custom.w = (NK_CURSOR_DATA_W*2)+1;
13758 atlas->custom.h = NK_CURSOR_DATA_H + 1;
13759 if (!nk_font_bake_pack(baker, &img_size, width, height, &atlas->custom,
13760 atlas->config, atlas->font_num, &atlas->temporary))
13763 /* allocate memory for the baked image font atlas */
13764 atlas->pixel = atlas->temporary.alloc(atlas->temporary.userdata,0, img_size);
13765 NK_ASSERT(atlas->pixel);
13766 if (!atlas->pixel)
13770 nk_font_bake(baker, atlas->pixel, *width, *height,
13771 atlas->glyphs, atlas->glyph_count, atlas->config, atlas->font_num);
13772 nk_font_bake_custom_data(atlas->pixel, *width, *height, atlas->custom,
13777 void *img_rgba = atlas->temporary.alloc(atlas->temporary.userdata,0,
13781 nk_font_bake_convert(img_rgba, *width, *height, atlas->pixel);
13782 atlas->temporary.free(atlas->temporary.userdata, atlas->pixel);
13783 atlas->pixel = img_rgba;
13785 atlas->tex_width = *width;
13786 atlas->tex_height = *height;
13789 for (font_iter = atlas->fonts; font_iter; font_iter = font_iter->next) {
13792 nk_font_init(font, config->size, config->fallback_glyph, atlas->glyphs,
13808 struct nk_cursor *cursor = &atlas->cursors[i];
13811 cursor->img.region[0] = (unsigned short)(atlas->custom.x + nk_cursor_data[i][0].x);
13812 cursor->img.region[1] = (unsigned short)(atlas->custom.y + nk_cursor_data[i][0].y);
13819 atlas->temporary.free(atlas->temporary.userdata, tmp);
13820 return atlas->pixel;
13824 if (tmp) atlas->temporary.free(atlas->temporary.userdata, tmp);
13825 if (atlas->glyphs) {
13826 atlas->permanent.free(atlas->permanent.userdata, atlas->glyphs);
13827 atlas->glyphs = 0;
13829 if (atlas->pixel) {
13830 atlas->temporary.free(atlas->temporary.userdata, atlas->pixel);
13831 atlas->pixel = 0;
13836 nk_font_atlas_end(struct nk_font_atlas *atlas, nk_handle texture,
13841 NK_ASSERT(atlas);
13842 if (!atlas) {
13849 null->uv.x = (atlas->custom.x + 0.5f)/(float)atlas->tex_width;
13850 null->uv.y = (atlas->custom.y + 0.5f)/(float)atlas->tex_height;
13852 for (font_iter = atlas->fonts; font_iter; font_iter = font_iter->next) {
13859 atlas->cursors[i].img.handle = texture;
13861 atlas->temporary.free(atlas->temporary.userdata, atlas->pixel);
13862 atlas->pixel = 0;
13863 atlas->tex_width = 0;
13864 atlas->tex_height = 0;
13865 atlas->custom.x = 0;
13866 atlas->custom.y = 0;
13867 atlas->custom.w = 0;
13868 atlas->custom.h = 0;
13871 nk_font_atlas_cleanup(struct nk_font_atlas *atlas)
13873 NK_ASSERT(atlas);
13874 NK_ASSERT(atlas->temporary.alloc);
13875 NK_ASSERT(atlas->temporary.free);
13876 NK_ASSERT(atlas->permanent.alloc);
13877 NK_ASSERT(atlas->permanent.free);
13878 if (!atlas || !atlas->permanent.alloc || !atlas->permanent.free) return;
13879 if (atlas->config) {
13881 for (iter = atlas->config; iter; iter = iter->next) {
13884 atlas->permanent.free(atlas->permanent.userdata, i->ttf_blob);
13887 atlas->permanent.free(atlas->permanent.userdata, iter->ttf_blob);
13893 nk_font_atlas_clear(struct nk_font_atlas *atlas)
13895 NK_ASSERT(atlas);
13896 NK_ASSERT(atlas->temporary.alloc);
13897 NK_ASSERT(atlas->temporary.free);
13898 NK_ASSERT(atlas->permanent.alloc);
13899 NK_ASSERT(atlas->permanent.free);
13900 if (!atlas || !atlas->permanent.alloc || !atlas->permanent.free) return;
13902 if (atlas->config) {
13904 for (iter = atlas->config; iter; iter = next) {
13909 atlas->permanent.free(atlas->permanent.userdata, i->ttf_blob);
13910 atlas->permanent.free(atlas->permanent.userdata, i);
13914 atlas->permanent.free(atlas->permanent.userdata, iter->ttf_blob);
13915 atlas->permanent.free(atlas->permanent.userdata, iter);
13917 atlas->config = 0;
13919 if (atlas->fonts) {
13921 for (iter = atlas->fonts; iter; iter = next) {
13923 atlas->permanent.free(atlas->permanent.userdata, iter);
13925 atlas->fonts = 0;
13927 if (atlas->glyphs)
13928 atlas->permanent.free(atlas->permanent.userdata, atlas->glyphs);
13929 nk_zero_struct(*atlas);
25685 /// - 2016/08/14 (1.09.2) - Fixed a bug in font atlas which caused wrong loading
25748 /// font atlas memory management by converting pointer