Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Possible bug in sf::Texture::LoadFromFile  (Read 1923 times)

0 Members and 1 Guest are viewing this topic.

Mikademus

  • Newbie
  • *
  • Posts: 31
    • View Profile
Possible bug in sf::Texture::LoadFromFile
« 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;
            }

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Possible bug in sf::Texture::LoadFromFile
« Reply #1 on: August 16, 2011, 08:11:09 am »
Absolutely.

It's fixed, thank you very much :)
Laurent Gomila - SFML developer

 

anything