关于Freetype缓存子系统的教程
Tutorial on Freetype cache subsystem
我正在尝试使用FreeType 2.4.11在我的项目中使用openGL渲染文本。
虽然我初始化库,面对和设置charmap为unicode只有一次。在每次绘制的字符循环中使用FT_Load_Char和glTexImage2D会使文本渲染减慢到不可接受的程度。
我需要一些如何在FreeType CacheSubSystem中缓存字形的适当示例,以避免渲染中的这种延迟
一次性初始化unicode的库、面和charmap,如下所示
if(m_FontLibrary == NULL)
{
if(!FT_Init_FreeType(&m_FontLibrary))
{
if(!FT_New_Face(m_FontLibrary, "C:\Windows\winsxs\amd64_microsoft-windows-f..etype-timesnewroman_31bf3856ad364e35_6.1.7601.17514_none_3b958c66aff6cdb7\times.ttf", 0, &m_FontFace))
{
FT_Set_Pixel_Sizes(m_FontFace, 0, 48);
if(!FT_Load_Char(m_FontFace, 'X', FT_LOAD_RENDER))
{
m_FontGlyph = m_FontFace->glyph;
if(!FT_Select_Charmap(m_FontFace, FT_ENCODING_UNICODE))
{
loaded = true;
}
}
}
}
}
在屏幕刷新率上,rendermodel函数调用DrawText函数,该函数循环遍历字符并加载字形并构建用于渲染的Image。
const char *text = "Tetrode ";
const char *p;
for(p = text; *p; p++)
{
// Load a single glyph into the glyph slot of a face object, according to its character code.
if(FT_Load_Char(m_FontFace, *p, FT_LOAD_RENDER))
continue;
// specify a two-dimensional texture image
glTexImage2D(
GL_TEXTURE_2D, // Target texture
0, // Base image level, Level n is the nth mipmap reduction image
GL_ALPHA, // Internal format
m_FontGlyph->bitmap.width, // Width of texture image
m_FontGlyph->bitmap.rows, // height of texture image
0, // Border, This value must be 0.
GL_ALPHA, // Format of the pixel data.
GL_UNSIGNED_BYTE, // Data type of the pixel data
m_FontGlyph->bitmap.buffer // Pointer to the image data in memory.
);
float x2 = x + m_FontGlyph->bitmap_left * sx;
float y2 = -y - m_FontGlyph->bitmap_top * sy;
float w = m_FontGlyph->bitmap.width * sx;
float h = m_FontGlyph->bitmap.rows * sy;
GLfloat box[4][4] = {
{x2, -y2 , 0, 0},
{x2 + w, -y2 , 1, 0},
{x2, -y2 - h, 0, 1},
{x2 + w, -y2 - h, 1, 1},
};
glBufferData(GL_ARRAY_BUFFER, sizeof box, box, GL_DYNAMIC_DRAW);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
x += (m_FontGlyph->advance.x >> 6) * sx;
y += (m_FontGlyph->advance.y >> 6) * sy;
}
我用FreeType做了一个项目,在那里我使用了缓存机制来加速绘图。不幸的是,我没有依赖内置缓存,而是自己创建了缓存。实际上,我所做的只是使用std::map并将字符与位图关联起来。
相关文章:
- 子系统中的异常处理:本机
- 使用mingw遵循简单的c ++ DLL教程时出错
- 虚幻文档中教程项目中的错误
- 编译C 电池收集器教程的错误
- 创建实例化所有其他类和子系统的类的目的是什么
- C/C++ 如何获取 USB libudev hidraw 设备的 USB 子系统路径?
- 当我使用的教程完全没有错误时,为什么我的代码错误
- 简单的教程SFML代码在Ubuntu 16.04上崩溃
- 我在哪里可以找到 Clang 的教程
- C++ 有没有关于如何使用句柄的教程?
- 编译 boost 文件系统的教程文件时遇到问题
- 使用生成器和发行版扩展c++11随机的教程或示例代码
- 试着学习巴基的教程
- 有没有关于如何将包含文件夹和文件的zip文件解压缩到某个目录并通过MiniZip将其打包的教程
- c++Why是关于字符串的教程中使用的一组字符
- 编写简单脚本语言的教程或介绍
- 关于Freetype缓存子系统的教程
- 7-Zip:任何好的教程
- 在哪里可以获得关于创建mpeg-1视频编码器的教程
- 当我尝试运行svm的教程时,get_support_vector_count的功能无法正常工作