mirror of
https://github.com/ApfelTeeSaft/vb01.git
synced 2026-08-26 19:33:45 +00:00
horizontal text
This commit is contained in:
@@ -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[] = {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user