diff --git a/src/graphics/components/BoxComponent.cpp b/src/graphics/components/BoxComponent.cpp index 22e5daf4f72a4dadf75d98a25003fc42839ad73e..72d764e18ec5e03d7315f68d00ed44ab90b829eb 100644 --- a/src/graphics/components/BoxComponent.cpp +++ b/src/graphics/components/BoxComponent.cpp @@ -186,6 +186,26 @@ void BoxComponent::resize(const int passedWindowWidth, const int passedWindowHei verticesDirty = true; } +void BoxComponent::changeColor(const unsigned int hexColor) { + // really a texture swap + + // set texture color + data[0][0][0] = (hexColor >> 24) & 0xFF; + data[0][0][1] = (hexColor >> 16) & 0xFF; + data[0][0][2] = (hexColor >> 8) & 0xFF; + data[0][0][3] = (hexColor >> 0) & 0xFF; + + glBindVertexArray(vertexArrayObject); + + // now replace existing texture + glBindTexture(GL_TEXTURE_2D, texture); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); + glGenerateMipmap(GL_TEXTURE_2D); + + glBindVertexArray(0); // unbind to prevent anything from accidentally changing it +} + /* void BoxComponent::resize(const int passedWindowWidth, const int passedWindowHeight) { diff --git a/src/graphics/components/BoxComponent.h b/src/graphics/components/BoxComponent.h index 1c04596b6de8cfc3e65a3ef4310d401fb292ae17..a4b980a1a88481b3ec31504ce7f4455b51809f36 100644 --- a/src/graphics/components/BoxComponent.h +++ b/src/graphics/components/BoxComponent.h @@ -27,6 +27,7 @@ public: BoxComponent(); BoxComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const unsigned int hexColor, const int passedWindowWidth, const int passedWindowHeight); ~BoxComponent(); + void changeColor(const unsigned int hexColor); virtual void render(); virtual void resize(const int passedWindowWidth, const int passedWindowHeight); };