TrueType Textures are now loading properly.

This commit is contained in:
2023-12-06 08:52:16 -06:00
parent e4da9b4d2f
commit 0b61be734d
4 changed files with 59 additions and 17 deletions

View File

@ -9,17 +9,21 @@
using namespace Dawn;
TrueTypeTexture::TrueTypeTexture(FT_Face face, uint32_t fontSize) :
face(face),
TrueTypeTexture::TrueTypeTexture(const uint32_t fontSize) :
fontSize(fontSize)
{
assertTrue(fontSize > 0, "Font size cannot be zero");
texture = std::make_shared<Texture>();
}
void TrueTypeTexture::setFace(const FT_Face face) {
this->face = face;
assertTrue(fontSize < 256, "Font size cannot be greater than 256");
texture = std::make_shared<Texture>();
// Set freetype font size prior to baking.
if(FT_Set_Pixel_Sizes(face, 0, fontSize)) {
assertUnreachable("Failed to set font size");
auto ret = FT_Set_Pixel_Sizes(face, 0, fontSize);
if(ret != 0) {
assertUnreachable("Failed to set font size %i", ret);
}
// Set the texture size
@ -126,5 +130,4 @@ struct TrueTypeCharacter TrueTypeTexture::getCharacterData(wchar_t c) {
}
TrueTypeTexture::~TrueTypeTexture() {
FT_Done_Face(this->face);
}

View File

@ -11,19 +11,27 @@
namespace Dawn {
class TrueTypeTexture final {
public:
private:
FT_Face face;
std::shared_ptr<Texture> texture;
uint32_t fontSize;
public:
std::shared_ptr<Texture> texture;
std::unordered_map<wchar_t, struct TrueTypeCharacter> characterData;
/**
* Construct a new New True Type Face Texture object
*
* @param face The freetype face object.
* @param fontSize The font size to render at.
* @param fontSize Size of the font.
*/
TrueTypeTexture(FT_Face face, uint32_t fontSize);
TrueTypeTexture(const uint32_t fontSize);
/**
* Sets the face for this texture.
*
* @param face Face to set.
*/
void setFace(const FT_Face face);
/**
* Returns the character data for the given character.