mirror of
https://github.com/devZoGok/vb01.git
synced 2026-08-26 19:43:30 +00:00
reading nonlatin characters
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
using namespace std;
|
||||
|
||||
namespace vb01{
|
||||
Text::Text(string fontPath, string entry){
|
||||
Text::Text(string fontPath, wstring entry){
|
||||
initFont(fontPath);
|
||||
setText(entry);
|
||||
}
|
||||
@@ -69,7 +69,11 @@ namespace vb01{
|
||||
|
||||
float advanceOffset = 0;
|
||||
for(int i = 0; i < entry.length(); i++){
|
||||
Glyph glyph = getGlyph(entry[i]);
|
||||
Glyph *glyphPtr = getGlyph(entry[i]);
|
||||
if(!glyphPtr)
|
||||
continue;
|
||||
|
||||
Glyph glyph = *glyphPtr;
|
||||
prepareGlyphs(glyph, advanceOffset);
|
||||
advanceOffset += glyph.size.x + glyph.bearing.x;
|
||||
}
|
||||
@@ -101,7 +105,7 @@ namespace vb01{
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
}
|
||||
|
||||
void Text::setText(string text){
|
||||
void Text::setText(wstring text){
|
||||
this->entry = text;
|
||||
|
||||
glGenVertexArrays(1, &VAO);
|
||||
@@ -115,15 +119,11 @@ namespace vb01{
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
Text::Glyph Text::getGlyph(char ch){
|
||||
Glyph glyph;
|
||||
for(Glyph g : characters)
|
||||
Text::Glyph* Text::getGlyph(u16 ch){
|
||||
Glyph *glyph = nullptr;
|
||||
for(Glyph &g : characters)
|
||||
if(g.ch == ch)
|
||||
glyph = g;
|
||||
glyph = &g;
|
||||
return glyph;
|
||||
}
|
||||
|
||||
float Text::getCharWidth(char c){
|
||||
return getGlyph(c).size.x * scale;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,25 +20,25 @@ namespace vb01{
|
||||
Vector2 size, bearing;
|
||||
};
|
||||
|
||||
Text(std::string, std::string);
|
||||
Text(std::string, std::wstring);
|
||||
~Text();
|
||||
void update();
|
||||
void setText(std::string);
|
||||
void setText(std::wstring);
|
||||
float getCharWidth(char);
|
||||
inline Node* getNode(){return node;}
|
||||
inline void setNode(Node *node){this->node = node;}
|
||||
inline void setScale(float s){this->scale = s;}
|
||||
inline void setColor(Vector4 c){this->color = c;}
|
||||
inline int getLength(){return entry.length();}
|
||||
inline std::string getText(){return entry;}
|
||||
inline std::wstring getText(){return entry;}
|
||||
private:
|
||||
void initFont(std::string);
|
||||
void prepareGlyphs(Glyph, float);
|
||||
void renderGlyphs(Glyph, float[], u32);
|
||||
Glyph getGlyph(char);
|
||||
Glyph* getGlyph(u16);
|
||||
|
||||
Node *node = nullptr;
|
||||
std::string entry;
|
||||
std::wstring entry;
|
||||
std::vector<Glyph> characters;
|
||||
Shader *shader = nullptr;
|
||||
unsigned int VAO, VBO;
|
||||
|
||||
Reference in New Issue
Block a user