Skip to content
Snippets Groups Projects
Commit fb231562 authored by Odilitime's avatar Odilitime
Browse files

changeColor()

parent 30d53f69
No related branches found
No related tags found
No related merge requests found
......@@ -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) {
......
......@@ -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);
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment