horizontal text

This commit is contained in:
devZoGok
2021-10-19 19:06:41 +03:00
parent 75d6273219
commit 808bb4cbfa
4 changed files with 20 additions and 13 deletions
+10 -5
View File
@@ -67,7 +67,7 @@ namespace vb01{
shader->setVec2(Vector2(width, height), "screen");
shader->setVec3(node->getPosition(), "pos");
float advanceOffset = 0;
Vector2 advanceOffset = Vector2::VEC_ZERO;
for(int i = 0; i < entry.length(); i++){
Glyph *glyphPtr = getGlyph(entry[i]);
if(!glyphPtr)
@@ -75,13 +75,18 @@ namespace vb01{
Glyph glyph = *glyphPtr;
prepareGlyphs(glyph, advanceOffset);
advanceOffset += glyph.size.x + glyph.bearing.x;
Vector2 size = glyph.size, bearing = glyph.bearing;
if(horizontal)
advanceOffset.x += (size.x + bearing.x);
else
advanceOffset.y += size.y;
}
}
void Text::prepareGlyphs(Glyph glyph, float advanceOffset){
Vector3 origin = node->getPosition();
origin.x += advanceOffset * scale;
void Text::prepareGlyphs(Glyph glyph, Vector2 advanceOffset){
Vector3 nodePos = node->getPosition();
Vector2 origin = Vector2(nodePos.x, nodePos.y);
origin = origin + (advanceOffset * scale);
Vector2 size = glyph.size * scale, bearing = glyph.bearing * scale;
float data[] = {
+1 -1
View File
@@ -8,5 +8,5 @@ uniform sampler2D tex;
uniform vec4 color;
void main(){
FragColor=vec4(color.xyz,texture(tex,texCoords).r);
FragColor = vec4(color.xyz, texture(tex, texCoords).r);
}
+4 -2
View File
@@ -24,16 +24,17 @@ namespace vb01{
~Text();
void update();
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::wstring getText(){return entry;}
inline bool isHorizontal(){return horizontal;}
inline void setHorizontal(bool h){this->horizontal = h;}
private:
void initFont(std::string);
void prepareGlyphs(Glyph, float);
void prepareGlyphs(Glyph, Vector2);
void renderGlyphs(Glyph, float[], u32);
Glyph* getGlyph(u16);
@@ -43,6 +44,7 @@ namespace vb01{
Shader *shader = nullptr;
unsigned int VAO, VBO;
float scale = 1;
bool horizontal = true;
Vector4 color = Vector4::VEC_IJKL;
};
}
+5 -5
View File
@@ -8,9 +8,9 @@ uniform vec2 screen;
uniform vec3 pos;
void main(){
float x,y;
x=(aVert.x-screen.x*.5)/(screen.x*.5);
y=(screen.y*.5-(aVert.y))/(screen.y*.5);
gl_Position=vec4(x,y,pos.z,1);
texCoords=aVert.zw;
float x, y;
x = (aVert.x - screen.x * .5) / (screen.x * .5);
y = (screen.y * .5 - (aVert.y)) / (screen.y * .5);
gl_Position = vec4(x, y, pos.z, 1);
texCoords = aVert.zw;
}