Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Drawing many different shapes? Or one shape changing in a loop and drawing?  (Read 2888 times)

0 Members and 1 Guest are viewing this topic.

DasOhmoff San

  • Guest
Hello, I just wanted to ask which operation would have theoreticly more performance.

Is it better to have for example 1000 different rectangle shapes that are drawn each frame.

Or is it better to have one single rectangle shape that gets changed in a loop and gets drawen 1000 times.
For example something like this:
for(sf::RectangleShape &shape : shapes)
{
    shape.setRotation(other_rotation);
    shape.setPosition(other_pos);
    shape.setFillColor(other_fill_color);
    shape.setOutlineColor(other_outline_color);

    window.draw(shape);
}

Which one is faster?
And what about sprites? Is it better to have 1000 sprites or one single sprite that gets changed every frame before drawing.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
You're asking the wrong question, because instead of sprites and rectangles, you should be using vertex arrays or buffers instead. The most expensive operation overall is the draw call, with a vertex array you reduce that from 1000 calls to a single call. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

DasOhmoff San

  • Guest
You're asking the wrong question, because instead of sprites and rectangles, you should be using vertex arrays or buffers instead. The most expensive operation overall is the draw call, with a vertex array you reduce that from 1000 calls to a single call. ;)

Ah I see, but how can I make a outline or a texture inside the rectangle then?
I think that is not possible with using vertecies only?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
It is possible (all the SFML shapes and their outlines are pretty much created using a vertex array) but you need to calculate those vertices manually.

This first vertex array tutorial may help you start off with them:
https://www.sfml-dev.org/tutorials/2.5/graphics-vertex-array.php

If you want separetad shapes on one vertex array, you'll need to use the sf::Triangles primitive and just specificy each of the three vertices of each triangle in the array.

You can texture vertex arrays too by specifying the texture coord in each vertex.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

DasOhmoff San

  • Guest
Ah ok, thank you!  ;D