I'm trying to load and display a character bitmap rendered by the freetype library.
FT_Library library;if (FT_Init_FreeType(&library)) { LogManager::GetInstance()->LogMessage("Could not initialize FreeType library.", LL_ERROR); return 0;}FT_Face face;unsigned int error;error = FT_New_Face(library, "tests/font/arialbd.ttf", 0, &face);if (error == FT_Err_Unknown_File_Format) { LogManager::GetInstance()->LogMessage("Unknown file format.", LL_ERROR);} else if (error) { LogManager::GetInstance()->LogMessage("Could not load font file.", LL_ERROR);}error = FT_Set_Char_Size(face, 25 << 6, 25 << 6, 96, 96);FT_Load_Glyph(face, FT_Get_Char_Index(face, 'A'), FT_LOAD_RENDER);FT_Bitmap& bitmap = face->glyph->bitmap;unsigned char* bitmapBuffer = new unsigned char[bitmap.width * bitmap.rows];for (unsigned int i = 0; i < bitmap.rows; i++) { for (unsigned int j = 0; j < bitmap.width; j++) { bitmapBuffer[j + i * bitmap.width] = bitmap.buffer[j + i * bitmap.width]; }}
The above code initializes the freetype library and loads a character in ('A' in this case).
After that, it gets the glyph's bitmap dimensions and allocates a buffer to store the glyph image.
Unfortunately, all I get is a distorted version of the character, as you can see from the following picture:
The weird thing is that for some other characters, it works just fine:
I really can't figure out what's wrong.
Thanks in advance!