我正在尝试运行 here 中的“7. 简单文本呈现”和“a. 基本代码”但函数“my_draw_bitmap”似乎未定义。我尝试使用 GLEW,但问题是一样的。然后我看到了“pngwriter”库here ,但是使用 Cmake 编译 Visual Studio 2013 会出错。
请有人帮忙,“my_draw_bitmap”函数在哪里定义?
教程说明
The function my_draw_bitmap
is not part of FreeType but must be provided by the application to draw the bitmap to the target surface. In this example, it takes a pointer to a FT_Bitmap descriptor and the position of its top-left corner as arguments.
这意味着您需要实现将字形复制到要自己渲染的纹理或位图中的功能(假设您正在使用的库中没有合适的功能可用)。
下面的代码应该适用于将单个字形的像素复制到可以复制到纹理的数组。
unsigned char **tex;
void makeTex(const unsigned int width, const unsigned int height)
{
tex = (unsigned char**)malloc(sizeof(char*)*height);
tex[0] = (unsigned char*)malloc(sizeof(char)*width*height);
memset(tex[0], 0, sizeof(char)*width*height);
for (int i = 1; i < height;i++)
{
tex[i] = tex[i*width];
}
}
void paintGlyph(FT_GlyphSlot glyph, unsigned int penX, unsigned int penY)
{
for (int y = 0; y<glyph->bitmap.rows; y++)
{
//src ptr maps to the start of the current row in the glyph
unsigned char *src_ptr = glyph->bitmap.buffer + y*glyph->bitmap.pitch;
//dst ptr maps to the pens current Y pos, adjusted for the current char row
unsigned char *dst_ptr = tex[penY + (glyph->bitmap.rows - y - 1)] + penX;
//copy entire row
for (int x = 0; x<glyph->bitmap.pitch; x++)
{
dst_ptr[x] = src_ptr[x];
}
}
}
我是一名优秀的程序员,十分优秀!