SFML VertexArray 不是 sf 的成员
SFML VertexArray not member of sf
我有以下程序用于绘制带有顶点数组的三角形,如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;
}
我使用的编译生成文件如下:
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
我不明白为什么它说顶点数组不是 sf 的成员!
您必须提供 SFML 库目录的路径和 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"
另一件事,为了能够看到一些东西,你应该用这样的东西来结束你的绘制调用:
while(1){
Mywindow.clear(sf::Color::Black);
Mywindow.draw(triangle);
Mywindow.display();
}
相关文章:
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- 对RValue对象调用的LValue ref限定成员函数
- 为什么使用 "this" 指针调用派生成员函数?
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 助记符和指向成员语法的指针
- 用于访问容器<T>数据成员的正确 API
- 内置函数可查看CPP中的成员变量
- 是否可以初始化不可复制类型的成员变量(或基类)
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 嵌套在类中时无法设置成员数据
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 将函数类成员映射到类本身内部
- 已定义或声明"sf::Unicode::Text::text"成员函数
- 类 sf::RenderWindow' 没有名为 'clear' 的成员
- SFML VertexArray 不是 sf 的成员
- 无法访问类 sf::不可复制中的私有成员.副本在哪里?C++
- sf::类的字符串成员恢复为空
- sf::Text 成员函数 getFont() 不起作用?
- c3867'sf::时间::作为秒':非标准语法;使用"&"创建指向成员的指针