Freetype2多个面孔
FreeType2 multiple faces
我正在使用freetype2库在OpenGL应用中实现字体。我的问题是,初始化一个FT_Face
对象会崩溃。我尝试使用FT_Library
的单个实例,并为每个新字体调用FT_Init_FreeType()
。我还尝试了每种字体的Havind单独的FT_Library
实例。这两个初始化都可以正常工作,但是随后我从malloc.c
获得了new
操作员的主张,无论下次,无论何处,都在下一行代码上。
这是字体对象创建方法,其中freetype2 lib初始化:
Font::Font* create(const char* path, unsigned int size) {
Font* font = new Font();
FT_Init_FreeType(&(font->_ft));
if(FT_New_Face(font->_ft, path, 0, font->_face)) {
std::cerr << "Font: Could not load font from file " << path << "." << std::endl;
return NULL;
}
FT_Set_Pixel_Sizes(*(font->_face), 0, size);
}
,如果我一次称呼它,那么这种代码的平静就可以了。如果我第二次打电话给它,然后在程序的另一部分中稍后拨打,我通过new
创建对象,应用程序崩溃。
这里有什么问题?应该有一些好方法来加载几个字体...
断言消息:malloc.c:2365: sysmalloc: Assertion (old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
更新:
字体类声明,ft库实例每个类别的版本:
class Font
{
public:
static Font* create(const char* font, unsigned int size);
void renderText(const wchar_t* text, float x, float y, float sx, float sy);
private:
Font();
~Font();
FT_Library _ft;
FT_Face* _face;
};
renderText()
方法基本使用_face窥视需要炭并渲染它们。
在呼叫FT_New_Face
之前,您确定font->_face
是新的吗?因此,如果font->_face
为null,则需要新的FT_Face
。
NOTE :对于每个字体实例,不需要启动FT_Library
。您可以使Font::_ft
成为静态。
最后,代码应为:
class Font
{
public:
static FT_Library _ft;
static Font* create(const char* path, unsigned int size)
{
Font* font = new Font();
if (Font::_ft == NULL)
if (FT_Init_FreeType(&Font::_ft))
return NULL;
if (font->_face == NULL)
font->_face = new FT_Face;
if (FT_New_Face(font->_ft, path, 0, font->_face)) {
std::cerr << "Font: Could not load font from file " << path << "." << std::endl;
return NULL;
}
FT_Set_Pixel_Sizes(*(font->_face), 0, size);
return font;
}
private:
// Set the member - _face to NULL when call constructor
Font() : _face(NULL) {}
~Font() { /* release the memory */ }
FT_Face* _face;
};
// Set the static member - _ft to NULL
FT_Library Font::_ft = NULL;
终于,您需要在呼叫驱动器时非专业化/发布有关freetype2的所有内存。
注意:FT_New_Face
的第四变量(FT_Face
)必须是实例。FT_New_Face
不为FT_Face
分配内存。
- 如何使用 freetype2 访问单色位图中的像素状态
- 如何使用libraqm使用FreeType2渲染正确的字形(阿拉伯语)
- 如何获取具有 Freetype2 的真正类型字体支持的代码点列表 C++
- 什么是用面部识别器opencv训练面孔以获得最佳效果的最佳方法
- 如何从Cube dexure夺回6个面孔
- 如何在Visual Studio中静态链接FreeType2
- Freetype2多个面孔
- 从ASCII到Unicode字符代码的转换(FreeType2)
- 使用 FreeType2 在 Eclipse CDT 中完成代码
- FreeType2 ft_outline_decomposition返回巨大的数字
- 使用opencvc++对相同的面孔进行分组