【问题标题】:SFML VertexArray not member of sfSFML VertexArray 不是 sf 的成员
【发布时间】:2014-05-02 18:53:14
【问题描述】:

我有以下程序用于绘制带有顶点数组的三角形,如 SFML 教程中所述。

#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    try{
        sf::RenderWindow Mywindow(sf::VideoMode(800,600),"TriColor Triangle!");


        sf::VertexArray triangle(sf::Triangles, 3);

        triangle[0].position = sf::Vector2f(5,5);
        triangle[1].position = sf::Vector2f(50,5);
        triangle[2].position = sf::Vector2f(50,50);

        triangle[0].color = sf::Color::Red;
        triangle[1].color = sf::Color::Blue;
        triangle[2].color = sf::Color::Green;

        Mywindow.draw(triangle);
    }
    catch( const std::runtime_error& e)
    {
        std::cout << e.what() << std::endl;
        std::cin.ignore();
        return EXIT_FAILURE;
    }

    std::cin.ignore();
    return EXIT_SUCCESS;
}

我正在使用的编译 Makefile 如下:

all:    exe

exe:    main.o
        g++ main.o -o exe -lsfml-graphics -lsfml-window -lsfml-system

main.o: main.cpp
        g++ -c main.cpp

正在显示以下错误:

make
g++ -c main.cpp
main.cpp: In function ‘int main()’:
main.cpp:11:2: error: ‘VertexArray’ is not a member of ‘sf’
main.cpp:11:18: error: expected ‘;’ before ‘triangle’
main.cpp:13:2: error: ‘triangle’ was not declared in this scope
main.cpp:21:11: error: ‘class sf::RenderWindow’ has no member named ‘draw’
main.cpp:23:33: error: expected unqualified-id before ‘&’ token
main.cpp:23:33: error: expected ‘)’ before ‘&’ token
main.cpp:23:33: error: expected ‘{’ before ‘&’ token
main.cpp:23:35: error: ‘e’ was not declared in this scope
main.cpp:23:36: error: expected ‘;’ before ‘)’ token
make: *** [main.o] Error 1

我不明白为什么它说 VertexArray 不是 sf 的成员!

【问题讨论】:

  • 它对我来说非常好用。确保您的系统上没有安装两个版本的 SFML。
  • 我猜我的系统没有完整安装 SFML。很多头文件都不存在。无论如何感谢您的回复!

标签: c++ sfml


【解决方案1】:

您必须提供 SFML lib 目录的路径和 SFML 包含目录的路径。

像这样:

"-IC:\\Path\\to\\your\\project\\your-lib-sub-dir\\SFML-2.1\\include"
"-LC:\\Path\\to\\your\\project\\your-lib-sub-dir\\SFML-2.1\\lib"

另外,为了能够看到某些东西,你应该在你的 draw call 周围加上这样的东西:

while(1){
    Mywindow.clear(sf::Color::Black);
    Mywindow.draw(triangle);
    Mywindow.display();
}

【讨论】:

  • 我猜我的系统没有完整安装 SFML。很多头文件都不存在。无论如何感谢您的回复!
  • 也许 my answer 在另一个 SFML 问题上可能会对您有所帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多