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

Author Topic: Drawing is too hard in sfml?  (Read 1802 times)

0 Members and 1 Guest are viewing this topic.

Dennis

  • Newbie
  • *
  • Posts: 3
    • View Profile
Drawing is too hard in sfml?
« on: February 18, 2017, 03:08:33 pm »
When i want to draw a simple rectangle i have to create an object for every single rectangle or draw the same object on multiple places is there any other way i can draw.

when i create a class with a draw function i can't just enter  window->draw_rectangle(x,y,width,height) i must create an object inside the class and set all its properties inside the constructor.

i can try to use the same object and change the value's before drawing it but there is no pop() or push() so i would have to reset everything manually.





 :-\

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Drawing is too hard in sfml?
« Reply #1 on: February 18, 2017, 03:13:47 pm »
SFML is more an object oriented library, however it's fairly easy to create a function/class that would more work the way you want.

Also C++ by itself is often more object oriented and less a functional programming language, so I suggest to adapt your logical thinking, rather than trying to force your model onto the language. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Drawing is too hard in sfml?
« Reply #2 on: February 18, 2017, 03:20:37 pm »
There are just too many options in each drawable class, to replace them with a single drawing function. There would be too many arguments, and you would probably have to set all of them, even the ones you don't care about.

Using drawing functions also means that you must store the drawing parameters on your side, so using classes helps you write less code by aggregating these parameters into single objects.

And of course if you really like drawing with functions rather than objects, you can easily write the corresponding functions yourself, with only the arguments that are relevant in your context.

void drawSomeStuff(sf::RenderTarget& target, arg1, arg2, arg3, ...)
{
    sf::SomeDrawable drawable;
    drawable.setStuff1(arg1);
    drawable.setStuff2(arg2);
    drawable.setStuff3(arg3);
    ...
    target.draw(drawable);
}
Laurent Gomila - SFML developer