0

Visual Studio Express 2012、CTP1 C++ コンパイラ

次のコードは機能します。画像をロードし、ウィンドウを閉じるまでウィンドウに表示します。

#include <memory>
#include <SFML/Graphics.hpp>
int main()
{
    sf::RenderWindow window(sf::VideoMode(800,600), "hello");

    auto Load = []() -> std::unique_ptr<sf::Texture> {
        std::unique_ptr<sf::Texture> tex_ptr(new sf::Texture);
        tex_ptr->loadFromFile("hello.png");
        return tex_ptr;
    };    
    auto tex_ptr = Load();
    sf::Sprite spr(*tex_ptr);

    while (window.isOpen())
    {
        sf::Event ev;
        while (window.pollEvent(ev))
        {
            if (ev.type == sf::Event::Closed)
                window.close();
        }    
        window.clear();
        window.draw(spr);
        window.display();
    }
}

次のコードでは、を使用して画像を非同期で読み込もうとしていますstd::async。これは、ラムダでロードが成功したことを示します。次に、外側で、未来からテクスチャを取得した後、テクスチャの他のプロパティを確認します。サイズは正しく印刷されます。ただし、画像は表示されません。コマンドで閉じる黒いウィンドウが表示されます。

#include <future>
#include <memory>
#include <iostream>
#include <SFML/Graphics.hpp>
int main()
{
    sf::RenderWindow window(sf::VideoMode(800,600), "hello");

    auto Load = []() -> std::unique_ptr<sf::Texture> {
        std::unique_ptr<sf::Texture> tex_ptr(new sf::Texture);
        if (tex_ptr->loadFromFile("hello.png"))
            std::cout << "load success\n";
        else
            std::cout << "load failure\n";
        return tex_ptr;
    };

    auto tex_ptr_future = std::async(std::launch::async, Load);

    auto tex_ptr = tex_ptr_future.get();
    sf::Sprite spr(*tex_ptr);

    // Oddly, this prints out exactly what I expect
    auto size = tex_ptr->getSize();
    std::cout << size.x << 'x' << size.y << '\n';

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

        window.clear();
        window.draw(spr); // nothin'
        window.display();
    }
}

誰かが私が間違っていることを見ていますか?

4

0 に答える 0