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

Author Topic: Reason: Unable to open file  (Read 10151 times)

0 Members and 1 Guest are viewing this topic.

Jaged

  • Newbie
  • *
  • Posts: 2
    • View Profile
Reason: Unable to open file
« on: July 04, 2021, 05:53:47 am »
I keep getting this error when I try to use "IncludeFromFile" for a sprite texture. I've tried to change the directory from shortened to full and change the picture just in case but it doesn't load the image.

I feel it is a mistake on my end like a mistake in calling the file or linking as I'm relatively new to both sfml and C++.

I'm using Visual studio 2019, and running a debug

   
int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 800), "Game"); //calls a window
    window.setVerticalSyncEnabled(true);
    sf::Texture t1;
    t1.loadFromFile("Images/whitePawn.png");
    sf::Sprite board(t1);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
   
        }

        window.clear(); //set black
        window.draw(board); //draw whats needed
        window.display(); //reset for new frame

    }
 

I hope someone can help  :D, Thanks in advance

Kvaz1r

  • Newbie
  • *
  • Posts: 39
    • View Profile
    • Email
Re: Reason: Unable to open file
« Reply #1 on: July 04, 2021, 08:46:38 am »
Can you check does example shader work for you?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Reason: Unable to open file
« Reply #2 on: July 04, 2021, 02:20:33 pm »
Probably your working directory is not correct.

IIRC, by default Visual Studio uses the output directory (where the .exe is created) and not the solution directory.
You can change the working directory in the project settings.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

kojack

  • Sr. Member
  • ****
  • Posts: 299
  • C++/C# game dev teacher.
    • View Profile
Re: Reason: Unable to open file
« Reply #3 on: July 04, 2021, 03:59:42 pm »
The default working directory for Visual Studio is $(ProjectDir), which is the directory where the .vcxproj file is located.
The setting for this is in the project properties under Debugging / Working Directory.

Common ones you can include in the setting:
$(ProjectDir) - Where the .vcxproj file is.
$(SolutionDir) - Where the .sln file is.
$(TargetDir) - Where the .exe is put during a build.
(Note: all of these expand to an absolute path with a slash on the end)

I tend to do all of my settings (intermediate, output, etc) relative to the .sln. So I use: $(SolutionDir)bin\
But $(TargetDir) would work too.

Jaged

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Reason: Unable to open file
« Reply #4 on: July 05, 2021, 07:55:29 am »
I don't know if the working directory is the issue because I've tried the full location of the file too and it gave the same error, and I am sure that's the file's
    sf::RenderWindow window(sf::VideoMode(800, 800), "Chess"); //calls a window
    window.setVerticalSyncEnabled(true);
    sf::Texture t1;
    t1.loadFromFile("C:/Users/jagdr/Downloads/Code/SFML Chess/Debug/Images/board.jpg");
    sf::Sprite board(t1);
 
name.

But if that is the issue how can I change the working directory?


 

anything