【问题标题】:FreeType2 my_draw_bitmap undefinedFreeType2 my_draw_bitmap 未定义
【发布时间】:2015-09-28 15:55:10
【问题描述】:

我正在尝试从here 运行“7. 简单文本渲染”和“a.基本代码”,但函数“my_draw_bitmap”似乎未定义。我尝试使用 GLEW,但问题是一样的。然后我看到了“pngwriter”库here,但是用Cmake编译Visual Studio 2013报错。

请人帮忙,'my_draw_bitmap'函数在哪里定义

【问题讨论】:

  • libpng 中没有定义。
  • 在哪里定义的?我发现 SDL_ttf 也是不错的工具。
  • 我无法回答它是在哪里定义的,但是由于您的问题是用 libpng 标记的,所以我回答了那部分。它不在 libpng 中。此外,字符串“draw_bitmap”在我拥有的最新 freetype 源(版本 2.5.3)中也没有。
  • 这是最愚蠢的事情。你在 freetype 中完成了一半的教程,然后他们甚至没有告诉你如何将文本呈现到屏幕上。

标签: c++ visual-studio-2013 libpng freetype


【解决方案1】:

教程说明

函数my_draw_bitmap 不是 FreeType 的一部分,但必须由应用程序提供以将位图绘制到目标表面。在此示例中,它采用指向 FT_Bitmap 描述符的指针及其左上角的位置作为参数。

这意味着您需要实现将字形复制到要自己渲染的纹理或位图的功能(假设您正在使用的库中没有合适的功能)。

下面的代码应该适用于将单个字形的像素复制到可以复制到纹理的数组中。

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];
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-31
    • 1970-01-01
    相关资源
    最近更新 更多