I ran into a problem, well several problems, when rendering textures with transparency in them.
The texture that I am drawing is 64x64 px and it contains a white square (around 40x40 px) surrounded by transparency (r: 0, g: 0, b: 0, a: 0, so basically black-transparent):
There are some weird black/grey lines around the edges of the inner square when rendering the texture, as can be seen in the image:
I mean the grey lines at those borders don't always occur on all four sides of the square. They are mostly on the vertical sides of the square. I have set the background of the window to white, so I can see the problem much better. From what I gather, OpenGL is just basically blending between border of transparency and non-transparency in the texture. So between the color of the square (1, 1, 1, 1) and the color of transparency (0, 0, 0, 0), it blends it to (0.5f, 0.5f, 0.5f, 0.5f) or something.
Now you might tell me to change the transparency of the texture to being white-transparent (1, 1, 1, 0). I have done that too. That will hide the lines for this specific texture. But if I had a black square in the texture, and a white-transparent background and a black window background, then I would start seeing those lines again. And that's one of the "side" problems. When I export through Photoshop, I get a transparent background who's color is (1, 1, 1, 0). But when I export the texture through Paint.NET, I get a transparent background which is (0, 0, 0, 0). But I can deal with this problem later. First I need my first problem fixed which is with OpenGL. And btw, I use Java and LWJGL 3, which supports OpenGL.
Here is some code:
id = glGenTextures();
bind();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
unbind();
I use stbi.
Here's my fragment shader:
#version 440 core
out vec4 color;
in vec4 v_color;
in vec2 v_uv;
uniform sampler2D sampler;
void main() {
color = texture(sampler, v_uv) * v_color;
}
v_color is just a color value that I can use to change the color of the texture. Rn it is just white.
My blending options are set to GL_ONE_MINUS_SRC_ALPHA.

