I load a texture in a PNG with transparency in my program with this code :
// Loading the image in a SDL_Surface
SDL_Surface* imageSDL = IMG_Load(m_imageFile.c_str());
if (imageSDL == 0)
{
std::cout << "Error while loading texture \"" << m_imageFile.c_str() << "\" : "
<< IMG_GetError() << std::endl;
return false;
}
SDL_Surface* invertedImage = invertPixels(imageSDL);
SDL_FreeSurface(imageSDL);
// Destruction of an eventual old texture
if(glIsTexture(m_id) == GL_TRUE)
glDeleteTextures(1, &m_id);
// ID Generation
glGenTextures(1, &m_id);
// Locking
glBindTexture(GL_TEXTURE_2D, m_id);
// Assessing format and internal format
GLenum internalFormat(0);
GLenum format(0);
// Assessing number of components (alpha or no alpha)
if (invertedImage->format->BytesPerPixel == 3)
{
internalFormat = GL_RGB;
if (invertedImage->format->Rmask == 0xff)
format = GL_RGB;
else
format = GL_BGR;
}
else if (invertedImage->format->BytesPerPixel == 4)
{
internalFormat = GL_RGBA;
if (invertedImage->format->Rmask == 0xff)
format = GL_RGBA;
else
format = GL_BGRA;
}
else
{
std::cout << "Error, unknown format of image \"" << m_imageFile.c_str() << "\" : "
<< SDL_GetError() << std::endl;
return false;
}
// pixels copying
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, invertedImage->w, invertedImage->h, 0, format, GL_UNSIGNED_BYTE, invertedImage->pixels);
// Filters application
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// Unlocking
glBindTexture(GL_TEXTURE_2D, 0);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
SDL_FreeSurface(invertedImage);
unfortunately, the transparent parts appear with some artifacts.
that's the mesh for a bit far (the window and the door are transparent) mesh
that's the window from up close window
do you know what might cause that?