0

I'm still new to FreeType, and at the moment, I'm just trying to save each glyph's bitmap into a png. I can loop through each glyph and save the png. But my main issue is just the fact that the bitmaps look really weird. I honestly don't know if it's meant to be like that (maybe it's a format), or it's just not reading the bitmap correctly.

FT_Library library;
FT_Face face;

auto error = FT_Init_FreeType(&library);
if (error) {
    LOGGER_LOG("FONT_RESOURCE", "Failed to initialize freetype library.");
    return;
}
error = FT_New_Face(library, path, 0, &face);
if (error == FT_Err_Unknown_File_Format) {
    LOGGER_LOG("FONT_RESOURCE", "Failed To Load Font, Unsupported File Format Detected.");
    return;
}

FT_Set_Pixel_Sizes(face, 0, 64);

FT_GlyphSlot slot = face->glyph;
for (unsigned int i = 0; i < face->num_glyphs; i++) {
    if (FT_Load_Char(face, i, FT_LOAD_RENDER)) continue;
    if (FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL)) continue;

    lodepng_encode32_file(std::string("CharacterTests/" + std::to_string(i) + ".png").c_str(), slot->bitmap.buffer, slot->bitmap.width, slot->bitmap.rows);
}

FT_Done_Face(face);
FT_Done_FreeType(library);

Here's all of my current code. It saves fine, just the result looks weird. For example, here's the A character:

A character

If someone could please just explain why this is happening, or even be able to help to push me in the right direction, that would be much appreciated. My next steps after this is to make a font atlas, but I think I already know how I'm gonna do that.

Evg
  • 25,259
  • 5
  • 41
  • 83
Stanlyhalo
  • 29
  • 7

0 Answers0