From 133b74699e803b7ab602d6ec10bf85fe5324808c Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Mon, 17 Apr 2023 20:13:03 +0200 Subject: [PATCH] add color in BufferVertex --- data/ofxGPUFont/shaders/DEBUG_ES3/font.frag | 3 ++- data/ofxGPUFont/shaders/DEBUG_ES3/font.vert | 3 +++ data/ofxGPUFont/shaders/ES3/font.frag | 3 ++- data/ofxGPUFont/shaders/ES3/font.vert | 3 +++ data/ofxGPUFont/shaders/GL3/font.frag | 3 ++- data/ofxGPUFont/shaders/GL3/font.vert | 3 +++ src/gpufont/font.hpp | 12 ++++++++---- 7 files changed, 23 insertions(+), 7 deletions(-) diff --git a/data/ofxGPUFont/shaders/DEBUG_ES3/font.frag b/data/ofxGPUFont/shaders/DEBUG_ES3/font.frag index 32c61d4..ca0413d 100644 --- a/data/ofxGPUFont/shaders/DEBUG_ES3/font.frag +++ b/data/ofxGPUFont/shaders/DEBUG_ES3/font.frag @@ -16,7 +16,7 @@ struct Curve { uniform isampler2D glyphs; uniform sampler2D curves; uniform sampler2D iChannel0; -uniform vec4 color; +//uniform vec4 color; // Controls for debugging and exploring: @@ -35,6 +35,7 @@ uniform bool enableControlPointsVisualization; in vec2 uv; flat in int bufferIndex; +in vec4 color; out vec4 result; diff --git a/data/ofxGPUFont/shaders/DEBUG_ES3/font.vert b/data/ofxGPUFont/shaders/DEBUG_ES3/font.vert index 96fc5ae..e756380 100644 --- a/data/ofxGPUFont/shaders/DEBUG_ES3/font.vert +++ b/data/ofxGPUFont/shaders/DEBUG_ES3/font.vert @@ -10,12 +10,15 @@ uniform float z; layout (location = 0) in vec2 vertexPosition; layout (location = 1) in vec2 vertexUV; layout (location = 2) in int vertexIndex; +layout (location = 3) in vec4 vertexColor; out vec2 uv; flat out int bufferIndex; +out vec4 color; void main() { gl_Position = projection * view * model * vec4(vertexPosition, z, 1.0); uv = vertexUV; bufferIndex = vertexIndex; + color = vertexColor; } diff --git a/data/ofxGPUFont/shaders/ES3/font.frag b/data/ofxGPUFont/shaders/ES3/font.frag index 4a3eee0..2bb4531 100644 --- a/data/ofxGPUFont/shaders/ES3/font.frag +++ b/data/ofxGPUFont/shaders/ES3/font.frag @@ -15,7 +15,7 @@ struct Curve { uniform isampler2D glyphs; uniform sampler2D curves; -uniform vec4 color; +//uniform vec4 color; // Controls for debugging and exploring: @@ -35,6 +35,7 @@ uniform bool enableControlPointsVisualization; in vec2 uv; flat in int bufferIndex; +in vec4 color; out vec4 result; diff --git a/data/ofxGPUFont/shaders/ES3/font.vert b/data/ofxGPUFont/shaders/ES3/font.vert index 96fc5ae..e756380 100644 --- a/data/ofxGPUFont/shaders/ES3/font.vert +++ b/data/ofxGPUFont/shaders/ES3/font.vert @@ -10,12 +10,15 @@ uniform float z; layout (location = 0) in vec2 vertexPosition; layout (location = 1) in vec2 vertexUV; layout (location = 2) in int vertexIndex; +layout (location = 3) in vec4 vertexColor; out vec2 uv; flat out int bufferIndex; +out vec4 color; void main() { gl_Position = projection * view * model * vec4(vertexPosition, z, 1.0); uv = vertexUV; bufferIndex = vertexIndex; + color = vertexColor; } diff --git a/data/ofxGPUFont/shaders/GL3/font.frag b/data/ofxGPUFont/shaders/GL3/font.frag index 5bcf06f..15c3bf2 100644 --- a/data/ofxGPUFont/shaders/GL3/font.frag +++ b/data/ofxGPUFont/shaders/GL3/font.frag @@ -13,7 +13,7 @@ struct Curve { uniform isamplerBuffer glyphs; uniform samplerBuffer curves; uniform sampler2D iChannel0; -uniform vec4 color; +//uniform vec4 color; // Controls for debugging and exploring: @@ -33,6 +33,7 @@ uniform bool enableControlPointsVisualization = false; in vec2 uv; flat in int bufferIndex; +in vec4 color; out vec4 result; diff --git a/data/ofxGPUFont/shaders/GL3/font.vert b/data/ofxGPUFont/shaders/GL3/font.vert index 5cd10fa..0f73ef5 100644 --- a/data/ofxGPUFont/shaders/GL3/font.vert +++ b/data/ofxGPUFont/shaders/GL3/font.vert @@ -8,12 +8,15 @@ uniform float z; layout (location = 0) in vec2 vertexPosition; layout (location = 1) in vec2 vertexUV; layout (location = 2) in int vertexIndex; +layout (location = 3) in vec4 vertexColor; out vec2 uv; flat out int bufferIndex; +out vec4 color; void main() { gl_Position = projection * view * model * vec4(vertexPosition, z, 1); uv = vertexUV; bufferIndex = vertexIndex; + color = vertexColor; } diff --git a/src/gpufont/font.hpp b/src/gpufont/font.hpp index 8e126a2..a0bed77 100644 --- a/src/gpufont/font.hpp +++ b/src/gpufont/font.hpp @@ -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 & variationText, std::vector & vertices, std::vector & 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 (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}); }