在sfml中使用vertexArray的正确方法是什么?
What is the correct way to use a vertexArray in sfml?
在做了一些研究之后,似乎使用vertexArrays以最有效的方式一次在屏幕上绘制许多精灵,但我正在努力如何做到这一点。我已经尝试使用sfml论坛,但我看到的每个例子都来自过时的代码,我有这个到目前为止。
int main()
{
sf::VertexArray lines(sf::LinesStrip, 4);
lines.append(sf::Vertex(sf::Vector2f(0, 0),sf::Vector2f(0, 0)));
lines.append(sf::Vector2f(0, 50));
lines.append(sf::Vector2f(250, 50));
lines.append(sf::Vector2f(250, 0));
sf::Texture text;
text.loadFromFile("Content/StartGame.png");
sf::RenderStates rend(&text);
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
// Start game loop
while (App.isOpen())
{
// Process events
sf::Event Event;
while (App.pollEvent(Event))
{
// Close window : exit
if (Event.type == sf::Event::Closed)
App.close();
}
App.clear();
App.draw(lines, &text);
App.display();
}
}
我有形状绘图,但当我试图应用到纹理时,没有绘制。
就像这样使用:
sf::VertexArray lines(sf::LinesStrip, 4);
lines[0].position = sf::Vector2f(10, 0);
lines[1].position = sf::Vector2f(20, 0);
lines[2].position = sf::Vector2f(30, 5);
lines[3].position = sf::Vector2f(40, 2);
window.draw(lines);
当你构造sf::Vector2f时,你没有提供任何纹理坐标;传递一些纹理坐标作为第三个参数,比如:
lines.append(sf::Vertex(sf::Vector2f(0, 0),sf::Vector2f(0, 0), sf::Vector2f(0,0)));
纹理坐标应该是类似于0,0
, 0,1
, 1,0
和1,1
。
您可能还必须将形状类型更改为sf::Quads
(因为我已经使用SFML有一段时间了,所以这可能是真的,也可能不是真的)。
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 实现无开销push_back的最佳方法是什么
- C++从另一个类访问公共静态向量的正确方法是什么
- 在 c++ 中拥有一组结构的正确方法是什么?
- 通过JNI传递数据数组的最快方法是什么
- 用常见虚拟函数实现的任意组合来实现派生类的正确方法是什么
- 使用不同的CRT将新的C++代码与旧的(二进制)组件隔离开来的最佳方法是什么
- 当无法使用模板和宏时,生成类型变体C++代码的最简单方法是什么?
- 在另一个类视图中添加最多2个图表的正确方法是什么
- 在C++中样板"冷/never_inline"错误处理技术的最佳方法是什么?
- 在 c++ 中对类中的 c 字符串动态数组进行排序的最佳方法是什么?
- 在C++中包含原型文件的正确方法是什么?
- 在 OpenCV C++ 中估计基本矩阵之前对相应点进行归一化的正确方法是什么?
- 在PostgreSQL中根据它们的ID选择大量行的最快方法是什么?
- 在OSX上使用CMake将Adobe的XMP工具包构建为共享库的最简单方法是什么?
- 将一系列整数放入类的最佳方法是什么?
- 从长整整转换为uint64_t的推荐方法是什么?
- 将此布尔值传递给此函数的最有效方法是什么?
- 通过比较C++中的行在 txt 文件中搜索的最简单方法是什么?