add color in BufferVertex

This commit is contained in:
jrkb 2023-04-17 20:14:39 +02:00
parent 74fed4e1f4
commit 8fe23edc1f
6 changed files with 27 additions and 18 deletions

View file

@ -50,6 +50,7 @@ void GPUFontAtlasLayerCombo::setup(const ComboIdentifier & identifier,
} }
void GPUFontAtlasLayerCombo::update(){ void GPUFontAtlasLayerCombo::update(){
for(const auto & layer : layers){ for(const auto & layer : layers){
layer->update();
if(layer->isDirtyDirty()){ if(layer->isDirtyDirty()){
isDirty = true; isDirty = true;
break; break;
@ -195,8 +196,6 @@ void GPUFontAtlasLayerCombo::draw(){
location = glGetUniformLocation(fontShaderProgram, "z"); location = glGetUniformLocation(fontShaderProgram, "z");
glUniform1f(location, z); glUniform1f(location, z);
location = glGetUniformLocation(fontShaderProgram, "color");
glUniform4f(location, 1.0f, 1.0f, 1.0f, 0.5f);
location = glGetUniformLocation(fontShaderProgram, "antiAliasingWindowSize"); location = glGetUniformLocation(fontShaderProgram, "antiAliasingWindowSize");
glUniform1f(location, (float)antiAliasingWindowSize); glUniform1f(location, (float)antiAliasingWindowSize);
@ -205,9 +204,6 @@ void GPUFontAtlasLayerCombo::draw(){
location = glGetUniformLocation(fontShaderProgram, "enableControlPointsVisualization"); location = glGetUniformLocation(fontShaderProgram, "enableControlPointsVisualization");
glUniform1i(location, enableControlPointsVisualization); glUniform1i(location, enableControlPointsVisualization);
//mouse.x = 0;
//mouse.y = 0;
std::vector <ofxGPUFont::Font::BufferVertex> vertices; std::vector <ofxGPUFont::Font::BufferVertex> vertices;
std::vector <int32_t> indices; std::vector <int32_t> indices;
@ -219,31 +215,21 @@ void GPUFontAtlasLayerCombo::draw(){
0)); 0));
font->collectVerticesAndIndices(node, font->collectVerticesAndIndices(node,
layer->getVariationText(), layer->getVariationText(),
vertices, indices, true, vertices, indices,
layer->getColor(),
true,
layer->getProps().fontSize_px); layer->getProps().fontSize_px);
} }
vertices.resize(totalCharacters * 4); vertices.resize(totalCharacters * 4);
indices.resize(totalCharacters * 6); indices.resize(totalCharacters * 6);
//cx = 0.5f * (bb.minX + bb.maxX);
//cy = 0.5f * (bb.minY + bb.maxY);
font->draw(vertices, indices); font->draw(vertices, indices);
//ofRectangle rectangle(0, 0, width, height);
//ofDrawRectangle(rectangle);
//font->draw(mouse.x, mouse.y - (200 * sin(ofGetElapsedTimef() * 0.25)), 0, "what", vFlip == V_FLIP_ON, 42.0f);
//location = glGetUniformLocation(fontShaderProgram, "color");
//glUniform4f(location, 0.0f, 1.0f, 0.0f, 0.5f);
//font->draw(mouse.x, mouse.y, 0, "ever", vFlip == V_FLIP_ON, 420.0f);
glUseProgram(currentProgram); glUseProgram(currentProgram);
} }
glDisable(GL_BLEND); glDisable(GL_BLEND);
//ofDrawBitmapStringHighlight(
//(ofToString("and we know:") + ofToString("everything"))
//, 100 + mouse.x, mouse.y, ofFloatColor::pink, ofFloatColor::black);
ofDrawBitmapStringHighlight( ofDrawBitmapStringHighlight(
"fps: " + ofToString(ofGetFrameRate()) + "\n" "fps: " + ofToString(ofGetFrameRate()) + "\n"
+ "font: " + this->identifier.fontPath + "\n" + "font: " + this->identifier.fontPath + "\n"

View file

@ -18,6 +18,12 @@ void GPUFontLayer::setup(const LayerSettings & settings){
} }
void GPUFontLayer::update(){ void GPUFontLayer::update(){
if(propsBuffer.size() > 0){
color = glm::vec4(propsBuffer[0].color[0],
propsBuffer[0].color[1],
propsBuffer[0].color[2],
propsBuffer[0].color[3]);
}
} }
void GPUFontLayer::draw(glm::vec3 position){ void GPUFontLayer::draw(glm::vec3 position){
@ -90,6 +96,9 @@ void GPUFontLayer::setProps(const Props & props){
const Layer::Props & GPUFontLayer::getProps() const { const Layer::Props & GPUFontLayer::getProps() const {
return propsBuffer[0]; // gets newest return propsBuffer[0]; // gets newest
} }
const glm::vec4 & GPUFontLayer::getColor() const {
return color;
}
void GPUFontLayer::clearPropsBuffer(){ void GPUFontLayer::clearPropsBuffer(){
propsBuffer.clear(); propsBuffer.clear();
} }

View file

@ -23,6 +23,7 @@ class GPUFontLayer : public Layer {
ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) override; ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) override;
void setProps(const Props & props) override; void setProps(const Props & props) override;
const Props & getProps() const override; const Props & getProps() const override;
const glm::vec4 & getColor() const;
void clearPropsBuffer() override; void clearPropsBuffer() override;
void setId(const LayerID & id) override; void setId(const LayerID & id) override;
const LayerID & getId() override; const LayerID & getId() override;
@ -63,5 +64,6 @@ class GPUFontLayer : public Layer {
ComboIdentifier momsComboIdentifier; ComboIdentifier momsComboIdentifier;
bool notHappyWithMom = false; bool notHappyWithMom = false;
LayerType type = GPUFONT; LayerType type = GPUFONT;
glm::vec4 color;
}; };
} }

View file

@ -59,6 +59,7 @@ class Layer {
ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) = 0; ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) = 0;
virtual void setProps(const Props & props) = 0; virtual void setProps(const Props & props) = 0;
virtual const Props & getProps() const = 0; virtual const Props & getProps() const = 0;
virtual const glm::vec4 & getColor() const = 0;
virtual void clearPropsBuffer() = 0; virtual void clearPropsBuffer() = 0;
virtual void setId(const LayerID & id) = 0; virtual void setId(const LayerID & id) = 0;
virtual const LayerID & getId() = 0; virtual const LayerID & getId() = 0;

View file

@ -16,6 +16,12 @@ void MsdfLayer::setup(const LayerSettings & settings){
} }
void MsdfLayer::update(){ void MsdfLayer::update(){
if(propsBuffer.size() > 0){
color = glm::vec4(propsBuffer[0].color[0],
propsBuffer[0].color[1],
propsBuffer[0].color[2],
propsBuffer[0].color[3]);
}
} }
void MsdfLayer::draw(glm::vec3 position){ void MsdfLayer::draw(glm::vec3 position){
@ -314,6 +320,9 @@ void MsdfLayer::setProps(const Props & props){
const Layer::Props & MsdfLayer::getProps() const { const Layer::Props & MsdfLayer::getProps() const {
return propsBuffer[0]; return propsBuffer[0];
} }
const glm::vec4 & MsdfLayer::getColor() const {
return color;
}
void MsdfLayer::clearPropsBuffer(){ void MsdfLayer::clearPropsBuffer(){
propsBuffer.clear(); propsBuffer.clear();
} }

View file

@ -22,6 +22,7 @@ class MsdfLayer : public Layer {
ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) override; ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) override;
void setProps(const Props & props) override; void setProps(const Props & props) override;
const Props & getProps() const override; const Props & getProps() const override;
const glm::vec4 & getColor() const;
void clearPropsBuffer() override; void clearPropsBuffer() override;
void setId(const LayerID & id) override; void setId(const LayerID & id) override;
const LayerID & getId() override; const LayerID & getId() override;
@ -54,5 +55,6 @@ class MsdfLayer : public Layer {
bool notHappyWithMom = false; bool notHappyWithMom = false;
ComboIdentifier momsComboIdentifier; ComboIdentifier momsComboIdentifier;
LayerType type = MSDFGEN; LayerType type = MSDFGEN;
glm::vec4 color;
}; };
} }