View Full Version : Issues with empty pixels and textures

07-22-2015, 06:30 AM
Hello! I am trying to map textures with empty pixels (not white pixels) to openGL rects. However, I am running into an issue. Almost all of the empty pixels are discarded, but a few white pixels remain around the edges of my texture, despite not being there in the image file. You can see the problem in the image attached below.


Here is the shader code I'm using to discard empty pixels:

#version 330 core
in vec2 TexCoords;

out vec4 color;

uniform sampler2D Texture;
uniform vec4 uniformColor;

void main()
vec4 texColor = texture(Texture, TexCoords) * uniformColor;
if(texColor.a < 0.1)

color = texColor;


And here is where I am loading textures, using the SOIL library.

GLuint loadTexture(const char* filePath)
int textureWidth, textureHeight;
GLuint texture;

//Generates the Texture ID and stores in var
glGenTextures(1, &texture);

//Binds the texture so future fx calls will affect this texture
glBindTexture(GL_TEXTURE_2D, texture);

//Loads the image using soil
unsigned char* image = SOIL_load_image(filePath, &textureWidth,
&textureHeight, 0, SOIL_LOAD_RGBA);

//Generates Texture info
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0,

//de allocates resources and unbinds texture
glBindTexture(GL_TEXTURE_2D, 0);

return texture;

Does anyone have any idea what might be causing this issue? Let me know if I could provide any other useful information, and thanks in advance for any help you can provide.

07-22-2015, 07:05 AM
Hello again. I crossposted this to reddit, and a helpful user Aransentin, pointed out that I was using Linear filtering, when I needed to be using nearest filtering.

I added the following code to my sprite's draw function:


and the problem was fixed.