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

Author Topic: The question of texture  (Read 1973 times)

0 Members and 1 Guest are viewing this topic.

roy1997

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
The question of texture
« on: June 30, 2016, 03:52:53 am »
The environment and the "SFML Work" program is tested successfully,but when I use the LoadFromFile()  in the texture class,there's some bugs.The console starts to brush the code and the windows is all white.I'm a green man.What's wrong on earth?God helps me.
#include <SFML/Graphics.hpp>
//#include<SFML/Graphics/Texture.hpp>

int main()
{
        sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!" );
       
       
        sf::Texture t;
        t.loadFromFile("D:\VS\TEST\ConsoleApplication1\Debug\1.png");
       

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

                window.clear();
                window.draw(shape);
                window.display();
        }

        return 0;
}

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: The question of texture
« Reply #1 on: June 30, 2016, 04:40:17 am »
See the notes on your code:

int main()
{
        sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!" );
       
       
        sf::Texture t;
        t.loadFromFile("D:\VS\TEST\ConsoleApplication1\Debug\1.png");

/* On windows the folder separator is  "\" but actually "\" is a character wildcard that
allows you to put anothers characters like \n  (line jump), so you need to put \\ like: "C:\\Demo.txt"
The correct way should be:
t.loadFromFile("D:\\VS\\TEST\\ConsoleApplication1\\Debug\\1.png");
*/
     

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

                window.clear();
                window.draw(shape); // Shape is not defined above.
                window.display();
        }

        return 0;
}
 
I would like a spanish/latin community...
Problems building for Android? Look here

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: The question of texture
« Reply #2 on: June 30, 2016, 04:45:05 am »
Although DarkRoku's suggestion of escaping the back-slash (doubling it) would technically fix the problem, it's much more portable - and a lot clearer - to just replace the back-slashes (\) with regular slashes (/). That way, it doesn't need escaping, doesn't need to be doubled and the code will work on a lot more systems.

tldr;
t.loadFromFile("D:\VS\TEST\ConsoleApplication1\Debug\1.png");
becomes
t.loadFromFile("D:/VS/TEST/ConsoleApplication1/Debug/1.png");

Note, though, that loadFromFile() returns a boolean that you should test. If it returns false, it failed to load the file.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

roy1997

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: The question of texture
« Reply #3 on: June 30, 2016, 05:14:33 am »
Thanks for you answering but I find that my code can be tested successfully on the other's computer.It seems that  vs 2013 is not Compatible and I must download the 2015 version.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: The question of texture
« Reply #4 on: June 30, 2016, 05:09:47 pm »
Either way, I would still recommend using only regular ("forward") slashes for paths in strings. I use Visual Studio myself; it really is the nicest way.
You can even see the problems back-slashes can cause in the posts on this thread. The paths with back-slashes have colour sectioned because those characters are getting "escaped".

The code you posted, by the way, is not complete (note that DarkRoku added a comment to the code that showed that shape was not actually created). It's not something someone can actually test. It can be much more helpful if you post the code you're actually having trouble with, preferably in the form of a minimal and complete example. You should try to run the complete code that you post here before posting  ;)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

roy1997

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: The question of texture
« Reply #5 on: July 01, 2016, 04:03:38 am »
Alright,when I put the code on the web,I wanted to delete some unused code for others to earlier understand,but the fact is that I didn't delete completely and I mean that even I change the slash there is also some bugs.My teacher says that the vs2013 is not compatible.Thank you all the same.(by the way it's the first time I ask a question on the internet,I feel very moved.) 

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: The question of texture
« Reply #6 on: July 01, 2016, 06:41:11 pm »
With what is VS2013 not compatible?
I use(d) VS2013 for years.

by the way it's the first time I ask a question on the internet,I feel very moved.
No worries. Just trying to help  :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything