使用std :: list存储顶点并使用SFML绘制它们

问题描述 投票:0回答:1

使用sfml,由于某些原因,我想将我的顶点存储在这样的列表中:

std::list<sf::Vertex> shape{};
shape.push_back(sf::Vertex(...);

但我真的不知道怎么打电话

window.draw(...);

我想它应该像这样的东西:

window.draw(shape.begin(), shape.size(), sf::LineStrip);

现在我猜它不起作用的原因是因为列表不支持随机访问......任何人都有想法吗?

c++ sfml vertex vertices stdlist
1个回答
2
投票

SFML期望顶点在连续存储中给出。你可以这样做:

std::vector<sf::Vertex> vec(shape.begin(), shape.end()); // copy
window.draw(vec.data, vec.size(), sf::LineStrip);

当然,首先使用vector(或VertexBuffer)会更有效率。

© www.soinside.com 2019 - 2024. All rights reserved.