Refactoring basic text rendering
This commit is contained in:
@@ -9,4 +9,4 @@ target_sources(Editor
|
||||
MeshLoader.h
|
||||
MeshLoader.cpp
|
||||
TextureLoader.h
|
||||
TextureLoader.cpp)
|
||||
TextureLoader.cpp "../../../tests/Engine/UI/Element.cpp")
|
||||
@@ -30,7 +30,6 @@ void FontLoader::importAsset(FontImportArgs args) {
|
||||
|
||||
// in case of the space character there is no bitmap
|
||||
// so we create a single pixel empty texture
|
||||
uint8 transparentPixel = 0;
|
||||
void FontLoader::import(FontImportArgs args, PFontAsset asset) {
|
||||
FT_Library ft;
|
||||
FT_Error error = FT_Init_FreeType(&ft);
|
||||
@@ -39,7 +38,6 @@ void FontLoader::import(FontImportArgs args, PFontAsset asset) {
|
||||
error = FT_New_Face(ft, args.filePath.string().c_str(), 0, &face);
|
||||
assert(!error);
|
||||
FT_Set_Pixel_Sizes(face, 0, 48);
|
||||
Array<Gfx::OTexture2D> usedTextures;
|
||||
for (uint32 c = 0; c < 256; ++c) {
|
||||
if (FT_Load_Char(face, c, FT_LOAD_RENDER)) {
|
||||
std::cout << "error loading " << (char)c << std::endl;
|
||||
@@ -49,28 +47,17 @@ void FontLoader::import(FontImportArgs args, PFontAsset asset) {
|
||||
glyph.size = IVector2(face->glyph->bitmap.width, face->glyph->bitmap.rows);
|
||||
glyph.bearing = IVector2(face->glyph->bitmap_left, face->glyph->bitmap_top);
|
||||
glyph.advance = face->glyph->advance.x;
|
||||
TextureCreateInfo imageData;
|
||||
imageData.format = Gfx::SE_FORMAT_R8_UINT;
|
||||
imageData.width = face->glyph->bitmap.width;
|
||||
imageData.height = face->glyph->bitmap.rows;
|
||||
imageData.sourceData.data = face->glyph->bitmap.buffer;
|
||||
imageData.sourceData.size = imageData.width * imageData.height;
|
||||
if (imageData.width == 0 || imageData.height == 0) {
|
||||
glyph.textureData.resize(glyph.size.x * glyph.size.y);
|
||||
if (glyph.textureData.size() == 0) {
|
||||
glyph.size.x = 1;
|
||||
glyph.size.y = 1;
|
||||
glyph.bearing.x = 0;
|
||||
glyph.bearing.y = 0;
|
||||
imageData.width = 1;
|
||||
imageData.height = 1;
|
||||
imageData.sourceData.size = sizeof(uint8);
|
||||
imageData.sourceData.data = &transparentPixel;
|
||||
glyph.textureData.add(0); // load a single transparent pixel, so that we dont have to handle empty textures later
|
||||
} else {
|
||||
std::memcpy(glyph.textureData.data(), face->glyph->bitmap.buffer, glyph.textureData.size());
|
||||
}
|
||||
glyph.textureIndex = usedTextures.size();
|
||||
usedTextures.add(graphics->createTexture2D(imageData));
|
||||
}
|
||||
FT_Done_Face(face);
|
||||
FT_Done_FreeType(ft);
|
||||
asset->setUsedTextures(std::move(usedTextures));
|
||||
|
||||
AssetRegistry::saveAsset(asset, FontAsset::IDENTIFIER, asset->getFolderPath(), asset->getName());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user