naive vFlip

This commit is contained in:
jrkb 2023-04-12 15:48:33 +02:00
parent c69c17899e
commit 48c64c9326

View file

@ -700,7 +700,7 @@ class Font {
} }
void draw(float x, float y, float z, const std::string & text){ void draw(float x, float y, float z, const std::string & text, bool vFlip = false){
float originalX = x; float originalX = x;
glBindVertexArray(vao); glBindVertexArray(vao);
@ -745,16 +745,27 @@ class Font {
float u1 = (float)(glyph.bearingX + glyph.width + d) / emSize; float u1 = (float)(glyph.bearingX + glyph.width + d) / emSize;
float v1 = (float)(glyph.bearingY + d) / emSize; float v1 = (float)(glyph.bearingY + d) / emSize;
float x0 = x + u0 * worldSize; float x0 = x + u0 * worldSize;
float y0 = y + v0 * worldSize; float y0 = y + v0 * worldSize;
float x1 = x + u1 * worldSize; float x1 = x + u1 * worldSize;
float y1 = y + v1 * worldSize; float y1 = y + v1 * worldSize;
if(vFlip){
float _v = v0;
v0 = v1;
v1 = _v;
y0 = y - v0 * worldSize;
y1 = y - v1 * worldSize;
}
int32_t base = static_cast <int32_t>(vertices.size()); int32_t base = static_cast <int32_t>(vertices.size());
vertices.push_back(BufferVertex{x0, y0, u0, v0, glyph.bufferIndex}); vertices.push_back(BufferVertex{x0, y0, u0, v0, glyph.bufferIndex});
vertices.push_back(BufferVertex{x1, y0, u1, v0, glyph.bufferIndex}); vertices.push_back(BufferVertex{x1, y0, u1, v0, glyph.bufferIndex});
vertices.push_back(BufferVertex{x1, y1, u1, v1, glyph.bufferIndex}); vertices.push_back(BufferVertex{x1, y1, u1, v1, glyph.bufferIndex});
vertices.push_back(BufferVertex{x0, y1, u0, v1, glyph.bufferIndex}); vertices.push_back(BufferVertex{x0, y1, u0, v1, glyph.bufferIndex});
indices.insert(indices.end(), {base, base + 1, base + 2, base + 2, base + 3, base}); indices.insert(indices.end(), {base, base + 1, base + 2, base + 2, base + 3, base});
} }