SFML community forums

Help => Network => Topic started by: JTeck on April 18, 2014, 08:39:11 am

Title: Load Sprite texture from Website
Post by: JTeck on April 18, 2014, 08:39:11 am
Hi,

What would be the easiest way to convert what I have here, to display my sprites textures instead of using .loadFromFile?

    sf::Http::Request request("image.png", sf::Http::Request::Post);

    sf::Http http("http://mysite.com/");
    sf::Http::Response response = http.sendRequest(request);

    // check the status
    if (response.getStatus() == sf::Http::Response::Ok)
    {
        // check the contents of the response
        std::cout << response.getBody() << std::endl;
    }
    else
    {
        std::cout << "request failed" << std::endl;
    }
 

This just shows the image.png contents in the console, I want to be able to draw a sprite from fetching the image from the website, is it possible to do this?

Cheers.
Title: Re: Load Sprite texture from Website
Post by: Jesper Juhl on April 18, 2014, 08:43:23 am
Two simple options:

1. Get the image from the website to a memory buffer, then use sf::Texture::loadFromMemory.
2. Save the image from the website to a file, then use sf::Texture::loadFromFile.
Title: Re: Load Sprite texture from Website
Post by: JTeck on April 18, 2014, 08:54:07 am
Two simple options:

1. Get the image from the website to a memory buffer, then use sf::Texture::loadFromMemory.
2. Save the image from the website to a file, then use sf::Texture::loadFromFile.

Can you justify how one could do this?
Title: Re: Load Sprite texture from Website
Post by: Laurent on April 18, 2014, 09:29:16 am
Don't you want to try by yourself first? ;)

It's really easy, and the doc + tutorials are more than enough to guide you.
Title: Re: Load Sprite texture from Website
Post by: JTeck on April 20, 2014, 02:20:50 am
Don't you want to try by yourself first? ;)

It's really easy, and the doc + tutorials are more than enough to guide you.

Can't find any good tutorials with a search :s
Title: Re: Load Sprite texture from Website
Post by: Laurent on April 20, 2014, 08:59:37 am
You won't find a tutorial that describes how to load a texture from a website. But you can find one about textures and one about the Http class, and the API documentation will do the rest. You already know which functions to use, so what's your problem? What have you already tried?