c++ - 使用 FreeType (DirectX 11) 绘制文本
问题描述
所以我想用 FreeType(在 DirectX 11 上)绘制文本。问题是我不太了解如何创建 my_draw_bitmap 函数(我遵循本教程)。
我得到所有字形,然后将它们转换为位图,但我看不到如何将 FT_Bitmap* 转换为 ID3D11Texture2D*(这在理论上允许我渲染文本)
这是我的代码:
字体加载器.cpp
void FontLoader::RenderText(ID3D11Device* p_device, Text* p_text, Math::Vec2 p_position)
{
const char* text = p_text->GetText();
FT_Face face = p_text->GetFont()->GetFace();
FT_GlyphSlot slot = face->glyph;
Math::Vec2 pen = p_position;
for (unsigned int i = 0; i < strlen(text); ++i)
{
if (FT_Load_Char(face, text[i], FT_LOAD_RENDER))
continue;
// draw to our target surface
CreateTextureFromBitmap(p_device, &slot->bitmap, Math::Vec2((float)slot->bitmap_left, (float)slot->bitmap_top));
// Increment pen position
pen._x += slot->advance.x >> 6;
}
}
ID3D11Texture2D* FontLoader::CreateTextureFromBitmap(ID3D11Device* p_device, FT_Bitmap* p_bitmap, Math::Vec2 p_position)
{
D3D11_TEXTURE2D_DESC textureDesc;
textureDesc.Width = p_bitmap->width;
textureDesc.Height = p_bitmap->pitch;
textureDesc.MipLevels = textureDesc.ArraySize = 1;
textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
textureDesc.SampleDesc.Count = 1;
textureDesc.Usage = D3D11_USAGE_DYNAMIC;
textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
textureDesc.MiscFlags = 0;
ID3D11Texture2D *texture2D = NULL;
// don't know how and when to use p_bitmap
p_device->CreateTexture2D(&textureDesc, NULL, &texture2D);
return texture2D;
}
非常感谢 !
解决方案
推荐阅读
- javascript - 使用 JavaScript 根据两个变量过滤卡片
- javascript - Javascript十进制舍入问题 - 精度
- python - 使用 flask-whooshalchemy 在 Flask 和 Python 中进行文本搜索
- angular - 如何从角度的守卫重定向到子路线
- r - 指标物种图(带分类轴的气泡图)
- reactjs - 使用`history.goBack()`时如何定义状态
- azure - Vsce 更新扩展,拒绝访问
- haskell - Haskell 模式匹配守卫
- python - 如何使用 numpy 获取范围的最小值和最大值?
- java - 我如何将字符串放入我的对象数组中?