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

Author Topic: Loading in small graphics  (Read 2780 times)

0 Members and 1 Guest are viewing this topic.

Anasky

  • Newbie
  • *
  • Posts: 20
    • View Profile
Loading in small graphics
« on: December 20, 2014, 01:37:11 pm »
Hey all,

I've got 540 images of 128 x 64 pixels. When I try to load the texture in with the following code:
        std::string Filepath;
        if (Filename.substr(1, 2) == ":\\" || Filename.substr(1, 2) == ":/"){
                Filepath = Filename;
        } else{
                Filepath = Main.AppPath + "../datafiles/GFX/" + Filename;
        }
        texture = new sf::Texture();
    texture->loadFromFile(Filepath);
        OriginalWidth = texture->getSize().x;
        OriginalHeight = texture->getSize().y;
        Width = OriginalWidth;
        Height = OriginalHeight;
[/cpp]
The texture->getSize() is 0 x 0. However, if I scale the image up to 128x128 or bigger, it loads just fine. Is this a known issue, and is there a fix?

Thanks in advance,
Anasky
« Last Edit: December 20, 2014, 02:25:45 pm by Laurent »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Loading in small graphics
« Reply #1 on: December 20, 2014, 02:04:51 pm »
This is probably an issue with your code.  You aren't checking loadFromFile's return value, so it may be as simple as you put the smaller image in the wrong folder and it couldn't find it.

Assuming that isn't it, could you provide a *complete* and minimal example (i.e., one we can actually compile and run ourselves without filling in a bunch of stuff, and without that odd Filename logic you have), the .png that is working for you and the .png that is not working for you?

Anasky

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Loading in small graphics
« Reply #2 on: December 20, 2014, 02:07:33 pm »
I managed to fix it by supplying a Width and Height. This'd mean that the getSize is bugging out, as the image is in fact loading (didn't figure that out until after it stopped trying to divide by Height (= 0)). And no, sorry, I can't really provide an empty environment :(

Anyhow, the issue's solved personally, although it's still a weird workaround.

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: Loading in small graphics
« Reply #3 on: December 21, 2014, 12:44:02 pm »
To find out whats wrong you should step through your code with the debugger and watch the values of all relevant variables!

PS: I would only use / for paths, as these need no escaping.

Anasky

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Loading in small graphics
« Reply #4 on: December 21, 2014, 01:51:12 pm »
I did step through it, and found that the loadFromFile function is executed, but the values stay 0 (even though they are in fact loaded). This is only the case for textures < 128 pixels height though.

And some computers start programs with \ in the path rather than /. I'm checking on both just to be sure.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Loading in small graphics
« Reply #5 on: December 21, 2014, 05:28:54 pm »
Always use forward slashes.  They work everywhere so you don't need hacks like that.