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

Author Topic: Unable to open file  (Read 7780 times)

0 Members and 1 Guest are viewing this topic.

ChrisPanov

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Unable to open file
« on: January 05, 2018, 01:56:06 am »
Hey everyone,

I'm new to SFML, and just bought that book about game programming with SFML,
but i have some problems.

Here is the code:

#include <SFML/Graphics.hpp>
using namespace sf;
int main()
{

        VideoMode vm(1920, 1080);

        RenderWindow window(vm, "Timber", Style::Fullscreen);

        Texture textureBackground;

        textureBackground.loadFromFile("assets/graphics/background.png");

        Sprite spriteBackground;

        spriteBackground.setTexture(textureBackground);

        spriteBackground.setPosition(0, 0);


        while (window.isOpen())
        {

                if (Keyboard::isKeyPressed(Keyboard::Escape))
                {
                        window.close();
                }

                window.clear();

                window.draw(spriteBackground);

                window.display();

        }

        return 0;
}


 


The thing is that i cant load the background.
This is the message i get: "The requested video mode is not available, switching to a valid mode
w╠їя          8     ". Reason: Unable to open file"

Where am i wrong?

And just to note, i've tried moving the png file everywhere and still no success
« Last Edit: January 05, 2018, 01:58:07 am by ChrisPanov »

Spirro

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: Unable to open file
« Reply #1 on: January 05, 2018, 07:23:20 am »
You didn't mention what IDE you are using to develope, but the path you have in your source may not be the path your IDE is using.  I think for VS the search path for files starts in the main directory of your project, but not 100% on that.  So your exe is looking for your lib in it's exe directory/assets/graphics/background.png.  Your IDE probably has a different start to that path.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Unable to open file
« Reply #2 on: January 05, 2018, 12:22:08 pm »
You shouldn't be using using namespace sf as it makes your code harder to read and can quickly lead to name conflicts.

The error message doesn't seem to make that much sense, as such I wonder whether you're wrongly linking libraries. Make sure you link the debug (-d suffix) libraries in debug mode and the release (no -d suffix) libraries in release mode.

And make sure your system can handle a resolution of 1920x1080.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ChrisPanov

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Unable to open file
« Reply #3 on: January 05, 2018, 08:26:17 pm »
I'm using Visual Studio 2017

Well ive done everything with the properties as it's shown in the book
The linker is okay i think

How could i change my start to the path?
What should i do?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Unable to open file
« Reply #4 on: January 05, 2018, 08:54:27 pm »
The book might simply be wrong, make sure to follow the official tutorial for setting up Visual Studio instead: https://www.sfml-dev.org/tutorials/2.4/
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ChrisPanov

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Unable to open file
« Reply #5 on: January 06, 2018, 12:52:50 am »
The thing is that the sample code works perfectly
Could there still be a problem with the linker with that in mind?

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Unable to open file
« Reply #6 on: January 06, 2018, 02:03:33 pm »
Back to C++ gamedev with SFML in May 2023

sp78

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Re: Unable to open file
« Reply #7 on: October 15, 2024, 06:08:33 pm »
I also found the same error, for future reference VS add space between ("graphics / background.png") - just put everything together ("graphics/background.png") and it works, for me at least.
« Last Edit: October 15, 2024, 06:16:38 pm by sp78 »