I've been playing around with FreeType to render text in OpenGL/DirectX. For debugging purposes, I'm wanting to render glyphs to a file (bmp, png, ect), so that I can pack them together as a font sprite sheet. To do this I'm using FreeImage. I'm creating a FreeImage bitmap via the FreeImage_ConvertFromRawBits function. Since FreeType generates 8 bit glyphs, I'm passing in 0 for the mask parameters for FreeImage_ConvertFromRawBits. See code below.
/* Initialize FreeType */
/* Create Face object */
/* Set character size */
int charCode = (int)'a';
int error = FT_Load_Char(face, charCode, FT_LOAD_RENDER);
/* Check for errors */
/* Initialize FreeImage */
int bpp = 8;
int width = face->glyph->bitmap.width;
int height = face->glyph->bitmap.rows;
int pitch = face->glyph->bitmap.pitch;
unsigned char* buffer = face->glyph->bitmap.buffer;
FIBITMAP* dib = FreeImage_ConvertFromRawBits(buffer, width, height, pitch, bpp, 0, 0, 0);
/* Check for errors */
FreeImage_Save(FIF_BMP, dib, "Glyph.bmp");
The issue is that the image comes out looking weird. You can kind of tell it looks like a glyph, but it's all messed up. If I try and save the image as a png, the image is still all messed up, but with random colors everywhere. I can't seem to find an example of saving a FreeType bitmap to an image file anywhere. Thanks!