So I have this problem: I am loading image with stbi_load()
and then creating texture with glTexImage2D()
. When I load .jpg
image, then everything works normaly, but when I load .png
, then the drawn image is black, where it should be transparent. Here is picture:
pictureOfWronglyDrawnPng
Here is code I have used:
Frist I set texture parametri:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Then I load the picture:
m_data = stbi_load(pathToTexture, &m_height, &m_width, &m_nrChannels, RGBA ? STBI_rgb : STBI_rgb_alpha);
And lastly I create texture and genarte mipMap:
glTexImage2D(GL_TEXTURE_2D, 0, RGBA ? GL_RGB : GL_RGBA, m_height, m_width, 0, RGBA ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, m_data);
glGenerateMipmap(GL_TEXTURE_2D);
RGBA
is bool that i set when i create Texture class
Here is also my fragment shader:
#version 330 core
out vec4 OutFrag;
uniform vec3 color;
uniform sampler2D tex;
in vec2 TexPos;
void main()
{
OutFrag = vec4(color, 1.0) * texture(tex, TexPos);
}
Does anyone know, why is the texture drawing incorrectly?