SFML community forums

General => General discussions => Topic started by: Mikademus on August 16, 2011, 12:37:45 am

Title: Possible bug in sf::Texture::LoadFromFile
Post by: Mikademus on August 16, 2011, 12:37:45 am
Hi, we're upgrading to SFML2 using the latest snapshot, thus we use the recent sf::Texture addition.

We have discovered a possible bug having to do with using the image pixel width rather than pitch in Texture::LoadFromImage.

This is the current code:
Code: [Select]
           // Copy the pixels to the texture, row by row
            const Uint8* pixels = image.GetPixelsPtr() + rectangle.Left + (width * rectangle.Top);
            GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
            for (int i = 0; i < rectangle.Height; ++i)
            {
                GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, i, myWidth, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
                pixels += width;
            }


It is very likely it should take pixel bit depth into consideration, that is width * 4 for a 32bpp RGBA pixel:
Code: [Select]
           // PITCH
            const Uint8* pixels = image.GetPixelsPtr() + 4 * (rectangle.Left + (width * rectangle.Top));

            GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
            for (int i = 0; i < rectangle.Height; ++i)
            {
                GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, i, myWidth, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels));

                // PITCH
                pixels += 4 * width;
            }
Title: Possible bug in sf::Texture::LoadFromFile
Post by: Laurent on August 16, 2011, 08:11:09 am
Absolutely.

It's fixed, thank you very much :)