【发布时间】:2019-11-16 19:50:35
【问题描述】:
我正在尝试将 FreeType GlyphSlot 位图转换为 Vulkan BGRA 格式。
void DrawText(const std::string &text) {
// WIDTH & HEIGHT == dst image dimensions
FT_GlyphSlot Slot = face->glyph;
buffer.resize(WIDTH*HEIGHT*4);
int dst_Pitch = WIDTH * 4;
for (auto c : text) {
FT_Error error = FT_Load_Char(face, c, FT_LOAD_RENDER);
if (error) {
printf("FreeType: Load Char Error\n");
continue;
}
auto char_width = Slot->bitmap.width;
auto char_height = Slot->bitmap.rows;
uint8_t* src = Slot->bitmap.buffer;
uint8_t* startOfLine = src;
for (int y = 0; y < char_height; ++y) {
src = startOfLine;
for (int x = 0; x < char_width; ++x) {
// y * dst_Pitch == Destination Image Row
// x * 4 == Destination Image Column
int dst = (y*dst_Pitch) + (x*4);
// Break if we have no more space to draw on our
// destination texture.
if (dst + 4 > buffer.size()) { break; }
auto value = *src;
src++;
buffer[dst] = 0xff; // +0 == B
buffer[dst+1] = 0xff; // +1 == G
buffer[dst+2] = 0xff; // +2 == R
buffer[dst+3] = value; // +3 == A
}
startOfLine += Slot->bitmap.pitch;
}
}
}
这给了我乱码的输出。我不确定我需要做什么才能正确转换为 Vulkan B8G8R8A8。我觉得在我们写入 Vulkan 纹理的缓冲区中从左到右移动是不正确的,也许 Vulkan 期望我以不同的方式将像素添加到缓冲区中?
我知道这段代码会把每个字母都写在另一个上面,在我可以正确绘制至少一个字母之后,我将实施利用Slot->advance。
【问题讨论】:
标签: c++ data-conversion vulkan freetype2