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

Author Topic: Do I really have to use std::vector<sf::CircleShape> ?  (Read 2671 times)

0 Members and 1 Guest are viewing this topic.

Sakman

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Do I really have to use std::vector<sf::CircleShape> ?
« on: July 17, 2018, 03:51:07 pm »


Hello! Lets say I have collection of circles that I want to draw. They are identical in color, outline etc. Like shown in the picture above.

Let's say I store the positions and radiuses in vectors. I don't want to store every sf::CircleShape individually since that takes too much memory and makes the program slow.

Is there a way to make a single sf::CircleShape and use (tranform?) something to move and scale the circle with the vectors mentioned above? And is there a way to draw them with a single RenderTarget::draw() like with sf::VertexArray?

Responses are greatly appreciated.

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Do I really have to use std::vector<sf::CircleShape> ?
« Reply #1 on: July 17, 2018, 04:01:09 pm »
Hello!
Hello! :)

I don't want to store every sf::CircleShape individually since that takes too much memory and makes the program slow.
How much memory do you think they take? Storing lots of circles shouldn't be slowing down your program. However, drawing lots of them may do that.

Is there a way to make a single sf::CircleShape and use (tranform?) something to move and scale the circle with the vectors mentioned above?
Yes, this is possible. You can create a single sf::CircleShape and modify it between each draw; this avoid the storage (but you still need to store where they are going to be somewhere) but makes the code messy (separating updating and drawing is a common 'tidy' approach).

And is there a way to draw them with a single RenderTarget::draw() like with sf::VertexArray?
sf::CircleShapes? No.
Two options that I can think of:
  • If the circles don't move (at all or maybe don't move much), draw them all to a single render texture and then you only need a single draw call to draw that render texture,
  • Create a vertex array and add the multiple circles to that vertex array; note that you will need to calculate the positions of all the points of each circle (you would probably use sf::Triangles for this)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Laurent Gomila - SFML developer

 

anything