add color in BufferVertex
This commit is contained in:
parent
c94acb14a2
commit
133b74699e
7 changed files with 23 additions and 7 deletions
|
@ -191,6 +191,7 @@ class Font {
|
|||
struct BufferVertex {
|
||||
float x, y, u, v;
|
||||
int32_t bufferIndex;
|
||||
float r, g, b, a;
|
||||
};
|
||||
|
||||
/// A structure to model a given axis of a variable font.
|
||||
|
@ -407,6 +408,8 @@ class Font {
|
|||
glVertexAttribPointer(1, 2, GL_FLOAT, false, sizeof(BufferVertex), (void *)offsetof(BufferVertex, u));
|
||||
glEnableVertexAttribArray(2);
|
||||
glVertexAttribIPointer(2, 1, GL_INT, sizeof(BufferVertex), (void *)offsetof(BufferVertex, bufferIndex));
|
||||
glEnableVertexAttribArray(3);
|
||||
glVertexAttribPointer(3, 4, GL_FLOAT, false, sizeof(BufferVertex), (void *)offsetof(BufferVertex, r));
|
||||
glBindVertexArray(0);
|
||||
|
||||
uploadBuffers();
|
||||
|
@ -874,6 +877,7 @@ class Font {
|
|||
const std::vector <GlyphIdentity> & variationText,
|
||||
std::vector <BufferVertex> & vertices,
|
||||
std::vector <int32_t> & indices,
|
||||
const glm::vec4 & color = glm::vec4(1),
|
||||
const bool vFlip = false,
|
||||
const float fontSize_px = 42){
|
||||
float advanceX = 0;
|
||||
|
@ -944,10 +948,10 @@ class Font {
|
|||
glm::vec4 p3 = node.getGlobalTransformMatrix() * glm::vec4(x0, y1 + advanceY, 0, 1);
|
||||
|
||||
int32_t base = static_cast <int32_t>(vertices.size());
|
||||
vertices.push_back(BufferVertex{p0.x, p0.y, u0, v0, glyph.bufferIndex});
|
||||
vertices.push_back(BufferVertex{p1.x, p1.y, u1, v0, glyph.bufferIndex});
|
||||
vertices.push_back(BufferVertex{p2.x, p2.y, u1, v1, glyph.bufferIndex});
|
||||
vertices.push_back(BufferVertex{p3.x, p3.y, u0, v1, glyph.bufferIndex});
|
||||
vertices.push_back(BufferVertex{p0.x, p0.y, u0, v0, glyph.bufferIndex, color.r, color.g, color.b, color.a});
|
||||
vertices.push_back(BufferVertex{p1.x, p1.y, u1, v0, glyph.bufferIndex, color.r, color.g, color.b, color.a});
|
||||
vertices.push_back(BufferVertex{p2.x, p2.y, u1, v1, glyph.bufferIndex, color.r, color.g, color.b, color.a});
|
||||
vertices.push_back(BufferVertex{p3.x, p3.y, u0, v1, glyph.bufferIndex, color.r, color.g, color.b, color.a});
|
||||
|
||||
indices.insert(indices.end(), {base, base + 1, base + 2, base + 2, base + 3, base});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue