SFML:Vector2<double> 无法编译。

3

我有一段代码编译不了。如果我将 sf::Vector2<double> 替换为 sf::Vector2f,它就能正常工作。我已经尝试过使用 typedef,但没有任何改变。

#include <SFML/Graphics.hpp>

int main() {
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");

    sf::Vertex line[] =
    {       
        sf::Vertex(sf::Vector2<double>(10.0, 10.0)),
        sf::Vertex(sf::Vector2<double>(150.0, 150.0))
    };

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

        window.clear();
        window.draw(line, 2, sf::Lines);
        window.display();
    }

    return 0;
}

第一个错误:
test.cpp: In function ‘int main()’:
test.cpp:9:47: error: no matching function for call to ‘sf::Vertex::Vertex(sf::Vector2<double>)’
1个回答

3

sf::Vertex 的构造函数不接受双精度向量,只接受浮点型向量。请参阅文档


为什么Vector2是模板呢?现在看起来好像没用。有没有办法使用double - Mangodile
1
它是模板化的,因为它也用于整数和无符号整数类型,例如Window::setPosition()采用Vector2i,而Window::setSize()采用Vector2u。对于绘制线条之类的事情,双精度并没有太多意义。 - ypnos

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接