假设我有一个Font
看起来像这样的类:
const unsigned int MAX_CHAR = 256; //better than dynamic I think?
struct BMchar
{
int x_ofs, y_ofs;
_uint32 x, y;
_uint32 width, height;
_uint32 x_advance;
};
struct BMkerninfo
{
_ushort first, second;
_ushort kerning;
};
class BM_FONT_CALL BMfont
{
public:
BMfont();
~BMfont(); //what will I free?
BMfont_Status Load(const char* fontName);
public:
float scale;
_uint32 tabSize;
_uint32 backTexture;
_uint32 frontTexture;
_uint32 textureSheet;
bool enableMasking;
bool hasBackground;
_uint32 base;
_uint32 lineHeight;
_uint32 pages;
_uint32 scaleW, scaleH;
_uint32 kerninfo_count;
BMkerninfo *kerninfo; //unused
BMchar chars[MAX_CHAR];
float texCoordBuff[MAX_CHAR * 8];
};
我有一堂课Label
:
class SWC_DLL SWC_Label
{
public:
SWC_Label ();
public:
void ShowText (const Point& basePoint, int baseW, int baseH);
public:
std::string text;
Point textCoord;
BMfont font;
T_Alignment textAlignment;
};
然后对于所有这些我担心,如您所见,该BMfont
课程使用大量资源。我将把类继承SWC_Label
给一个类SWC_Button
(是的,一个按钮,上面有标签/文本)。
现在,我希望它SWC_Button
具有具有不同字体的功能。做这种事情的更好和内存效率更高的方法是什么,我应该做一个限制,比如:只制作定义数量的可用字体(在类标签中制作静态字体)?
注意:我正在使用 OpenGL 制作 UI