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

Author Topic: Load Sprite texture from Website  (Read 3139 times)

0 Members and 1 Guest are viewing this topic.

JTeck

  • Newbie
  • *
  • Posts: 35
    • View Profile
Load Sprite texture from Website
« 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.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Load Sprite texture from Website
« Reply #1 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.

JTeck

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Load Sprite texture from Website
« Reply #2 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Load Sprite texture from Website
« Reply #3 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.
Laurent Gomila - SFML developer

JTeck

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Load Sprite texture from Website
« Reply #4 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Load Sprite texture from Website
« Reply #5 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?
Laurent Gomila - SFML developer

 

anything