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 232 times)

0 Members and 1 Guest are viewing this topic.

DasOhmoff San

  • Newbie
  • *
  • Posts: 20
    • View Profile
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: 9353
    • 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
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

DasOhmoff San

  • Newbie
  • *
  • Posts: 20
    • View Profile
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: 2788
  • My number of posts is shown in hexadecimal.
    • View Profile
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
Kairos - Timing Library
Rectangular Boundary Collision - Rectangular SAT Collision

@Hapaxiation - Hapaxia on Twitter

DasOhmoff San

  • Newbie
  • *
  • Posts: 20
    • View Profile
Ah ok, thank you!  ;D

 

anything