Answer the question
In order to leave comments, you need to log in
How to draw glyph (freetype) pixel by pixel?
I'm using a pixel buffer which has 3 bytes per pixel (rgb) and is organized line by line.
game.viewWidth - screen width in pixels.
buffer is the output image that is drawn to the screen.
I'm initializing the freetype library and trying to render a small letter 'a'.
But instead of 'a' I get some lines obliquely:
Killed 6 hours, did not understand anything. What am I doing wrong? All the tutorials say this code should work.
FT_Library ft;
FT_Face face;
if (FT_Init_FreeType(&ft))
std::cout << "ERROR::FREETYPE: Could not init FreeType Library" << std::endl;
if (FT_New_Face(ft, "fonts/arial.ttf", 0, &face))
std::cout << "ERROR::FREETYPE: Failed to load font" << std::endl;
FT_Set_Pixel_Sizes(face, 0, 72);
FT_Load_Char(face, 'a', FT_LOAD_RENDER))
std::cout << "ERROR::FREETYTPE: Failed to load Glyph" << std::endl;
FT_GlyphSlot ch = face->glyph;
for (int rows = 0; rows < ch->bitmap.rows; rows++)
{
for (int yi = 0; yi < ch->bitmap.width; yi++)
{
buffer[rows*game.viewWidth * 3 + yi * 3] = ch->bitmap..buffer[(rows * ch->bitmap.pitch + yi) ];
buffer[rows*game.viewWidth * 3 + yi * 3 + 1] = ch->bitmap.buffer[(rows * ch->bitmap.pitch + yi)];
buffer[rows*game.viewWidth * 3 + yi * 3 + 2] = ch->bitmap.buffer[(rows * ch->bitmap.pitch + yi)];
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question