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

Author Topic: Can't load images  (Read 3892 times)

0 Members and 1 Guest are viewing this topic.

rinzlerFix

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Can't load images
« on: July 13, 2016, 01:20:36 am »
Hi guys,

I have a fresh Ubuntu Mate install on one of my machines and a I can't load/display images.

#include <SFML/Graphics.hpp>

int main()
{
    // Create the main window
    sf::RenderWindow app(sf::VideoMode(800, 600), "SFML window");

    // Load a sprite to display
    sf::Texture texture;
    if (!texture.loadFromFile("cb.bmp"))
        return EXIT_FAILURE;
    sf::Sprite sprite(texture);

        // Start the game loop
    while (app.isOpen())
    {
        // Process events
        sf::Event event;
        while (app.pollEvent(event))
        {
            // Close window : exit
            if (event.type == sf::Event::Closed)
                app.close();
        }

        // Clear screen
        app.clear();

        // Draw the sprite
        app.draw(sprite);

        // Update the window
        app.display();
    }

    return EXIT_SUCCESS;
}
 

Everytime a try to execute the code I get a segmentation fault, but if a put a wrong path for the image (like "cb2.bmp") I get "Failed to load image "cb2.bmp". Reason: Unable to open file."

If a comment every line mentioning "texture" and "sprite", the program runs but obviosly I get a black screen.

I get the same results compiling directly from the console.

I've faced the same issues long ago on a previous Linux distro ("lubuntu"), but I fixed somehow. Driver issues?



Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Can't load images
« Reply #1 on: July 13, 2016, 01:41:21 am »
Are you sure that the image is in the directory in that it is looking? The current working directory can be not the one you expect. Try specifying the fully-qualified filename (including drive and path).

Try other images too. It's possible that the image is just not working. SFML's image loader doesn't support all versions of image file types. Try, for example, the SFML logo PNG. If it is the image, try loading it in an editor and then saving it, trying other formats.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

rinzlerFix

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Can't load images
« Reply #2 on: July 13, 2016, 02:03:45 am »
I've tested other images and no luck, also getcwd() gives me right path.

I was working on a little game project and I can't run it because of this problem, I remember that I've installed some composition software, and some other stuff on other machine with the same problem and suddenly this was fixed.

Machine specs,
Intel(R) Core(TM)2 Duo CPU E7500 @ 2.93GHz
RAM 2GiB
G72 [GeForce 7500 LE]

[Edit]

If a change the default graphics driver to the nvidia a get another error, shown on the attached files.

Ps: Sorry about my English.
« Last Edit: July 13, 2016, 02:53:26 am by rinzlerFix »

rinzlerFix

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Can't load images
« Reply #3 on: July 13, 2016, 03:14:03 am »
Sorry for the double post, but I managed to fix the problem.

I switched to nvidia drivers, installed mesa vdpau and it works now  ;D

Thanks anyway Hapax

 

anything