SFML community forums

Help => Graphics => Topic started by: Rozdarty on December 08, 2020, 01:04:16 am

Title: Textures not loading, and I tried EVERYTHING
Post by: Rozdarty on December 08, 2020, 01:04:16 am
Yes, I included the file type (png), yes I tried making a sprite, yes I have it in the same folder as the "Source.cpp" file. I am getting so frustrated as I have wasted the past hour or so trying to figure out why it is doing this. I am thinking it might be the way I linked the project? The thing is, though, every other type of code works with these project settings, EXCEPT adding textures.
Any ideas?
Thanks.

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>

int main()
{
        sf::RenderWindow window(sf::VideoMode(800, 800), "Good");
        sf::Texture texture;
        texture.loadFromFile("sfml logo.png");
        sf::Sprite sprite;
        sprite.setTexture(texture);
        sprite.setColor(sf::Color::Red);

        while (window.isOpen())
        {
                sf::Event ev;
                while (window.pollEvent(ev))
                {
                        if (ev.type == sf::Event::Closed)
                        {
                                window.close();
                        }
                }
                window.clear();
                window.draw(sprite);
                window.display();
        }
}
 
Title: Re: Textures not loading, and I tried EVERYTHING
Post by: G. on December 08, 2020, 02:35:22 am
Any error message? Something in the console? Have you tried checking the return value of loadFromFile?
WTF happens when you run your code... we don't know
Title: Re: Textures not loading, and I tried EVERYTHING
Post by: Rozdarty on December 08, 2020, 03:08:32 am
I get the usual unhandled exception error with the random symbols in the console, the usual error you get when the compiler can't recognize the texture file.
Title: Re: Textures not loading, and I tried EVERYTHING
Post by: G. on December 08, 2020, 04:49:47 am
Random symbols in the console usually happens when you're mixing debug and release. (when you're using the release version of SFML but compiling in debug mode, or debug version and compiling in release mode)