Skip to content

[rtext] GenImageFontAtlas() default package method is very strict for atlas height #5542

@vitassuper

Description

@vitassuper

Issue description

I’m trying to load the NotoSans-Regular.ttf font with the default codepoints plus a few additional Cyrillic codepoints. The font size is 96. Interestingly, if I use another size (e.g., 100), the issue disappears.

This problem occurs randomly—it seems to depend on the font size and the number of codepoints being loaded. When adding more codepoints or changing the font size, the issue sometimes goes away.

In the terminal, I also see:
WARNING: FONT: Failed to package character (103)

After investigating, I noticed that the code which checks the atlas height is quite strict:

rtext.c:844

if (totalArea < ((imageSize*imageSize)/2))

I have some draft improvements to make this check slightly more flexible, which could reduce edge cases like this. If you’re open to improving this algorithm, I’d be happy to submit a PR.

Environment

MacOS 12.7.6
Raylib 5.5
OpenGL 4.1 INTEL-18.8.16

Issue Screenshot

Image

Code Example

FontWrapper *load_font(const char *font_path, int font_size) {
  FontWrapper *wrapper = malloc(sizeof(FontWrapper));
  wrapper->font_path = font_path;
  wrapper->font_size = font_size;
  int default_codepoints[95 + 9];

  for (int i = 0; i < 95; i++) {
    default_codepoints[i] = 32 + i;
  }

  int size = 0;
  int * codepoints = LoadCodepoints("йцукенгшщ", &size);
  for (int i = 0; i < 9; i++) {
    default_codepoints[95+i] = codepoints[i];
  } 
  wrapper->raylib_font = LoadFontEx(font_path, font_size, default_codepoints, 95+9);

  return wrapper;
}

FontWrapper *font = load_font("NotoSans-Regular.ttf", 96);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions