0
votes

I am trying to make it possible for my GUIs to change color in game, without having to load in a new texture. Here is how I have it implemented as of now.

I get the color of the texture using Sampler2D in the fragment shader, then with the help of some uniform variables,

uniform int maxSwapColors;
uniform bool colorSwap;
uniform vec3 textureColors[3];
uniform vec3 toBeColors[3];

I check to see if the fragment's color should be changed, i.e. that it is equal to a color within textureColors. Where textureColor is the color of the actual preloaded texture gathered from the Sampler2D.

for(int i = 0; i < maxSwapColors; i++) {
        if(textureColor.xyz == textureColors[i]) {
            textureColor.xyz = toBeColors[i];
        }
    }

This works except for one problem.

enter image description here

The color switches almost completely except for 4 bands of color where it blends for some reason. The actual texture is comprised of two colors full red and full green. In these bands you can see the color of the preloaded texture.

enter image description here

I assume that the blending is occuring because of OpenGL at some point but I do not know where or why. And this occurs even when I GL11.glDisable(GL11.GL_BLEND);

I have tried using glsl's greaterThan() and lessThan() methods to create a range for textureColors. This makes the bands smaller but does NOT completely remove them, so I am looking for a more comprehensive solution.

Thank you, and any help is appreciated!

1

1 Answers

1
votes

The blending occurs because your texture uses linear filtering. Use nearest filtering instead.

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);