gpt4 book ai didi

c - 为什么 FT_Load_Char 给我一个垃圾字形位图?

转载 作者:太空宇宙 更新时间:2023-11-04 03:09:53 25 4
gpt4 key购买 nike

当我调用 FT_Load_Char 时,字体的字形槽中有位图的垃圾数据,每次运行程序时都会发生变化。

我已确保 FT_Init_FreeType 和 FT_New_Face 成功返回。我已经使用 FT_Set_Pixel_Sizes(face, 0, 48) 设置了像素大小。正在使用 FT_LOAD_RENDER 调用 FT_Load_Char 函数并成功返回。我还尝试下载 freetype2 的源代码并自己构建它,以防它的 pacman 分发版(对于 MinGW64)被破坏。

// Note: I've removed some irrelevant declarations
void fill_text(const char *text, int x, int y) {
static bool freetype_initialized = false;
static FT_Library ft = NULL;
static FT_Face face = NULL;
if (!freetype_initialized) {
!FT_Init_FreeType(&ft)
|| error("failed to initialize freetype library");
!FT_New_Face(ft, "VeraMono.ttf", 0, &face)
|| error("failed to load font");
FT_Set_Pixel_Sizes(face, 0, 48);
for (int c = 32; c < 128; c++) {
if (FT_Load_Char(face, c, FT_LOAD_RENDER)) {
warning("failed to load character '%c'\n", c);
continue;
}
printf("%c = %i, %I\n", c
face->glyph->bitmap.width,
face->glyph->bitmap.rows);
...

输出最终是这样的:

wajid@DESKTOP-0TJ0HS4 MINGW64 ~/src/cgame
$ ./cgame.exe
= 0, 39226112
! = 0, 39226112
" = 0, 39226112
# = 0, 39226112
$ = 0, 39226112
% = 0, 39226112
& = 0, 39226112
' = 0, 39226112
( = 0, 39226112
) = 0, 39226112
* = 0, 39226112
+ = 0, 39226112
, = 0, 39226112
- = 0, 39226112
. = 0, 39226112
/ = 0, 39226112
0 = 0, 39226112
1 = 0, 39226112
2 = 0, 39226112

每隔一段时间,垃圾就已经够糟了,它只会让程序崩溃。我希望获得具有适当指标的位图,我可以使用它来使用 OpenGL 呈现文本。

最佳答案

事实证明我的代码没有任何问题。在 MinGW64 上使用 pacman 时,与 freetype 一起安装的依赖项之一实际上存在一个错误。它可以是 harfbuzz、graphite2、glib2、pcre 或 wineditline。

值得庆幸的是,该库仍然可以在不安装这些的情况下从源代码构建。这样做,错误就会消失。

关于c - 为什么 FT_Load_Char 给我一个垃圾字形位图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57451714/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com