gpt4 book ai didi

c++ - 在 sfml 中使用 vertexArray 的正确方法是什么?

转载 作者:太空宇宙 更新时间:2023-11-04 16:22:15 25 4
gpt4 key购买 nike

经过一些研究后发现,使用 vertexArrays 似乎是一次将许多 Sprite 绘制到屏幕上的最有效方式,但我正在努力如何去做。我曾尝试使用 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);

关于c++ - 在 sfml 中使用 vertexArray 的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15557293/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com