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

Author Topic: change View or change RenderStates?  (Read 2260 times)

0 Members and 1 Guest are viewing this topic.

Tyrendel

  • Newbie
  • *
  • Posts: 10
    • View Profile
change View or change RenderStates?
« on: April 26, 2021, 11:34:45 am »
Hello,

I'm working on a lunar lander (video bellow) and I manage to achieve the same camera movements either by moving the view or by changing RenderStates. I don't clearly understand which way I should go. I've read the doc and searched on the forum and google but I didn't find similar questions.

1) Is there a concrete reason one should be used over the other depending on the use case (code organisation and readability, ...) or is it more a philosophical choice?
2) What is the perf impact of changing the View VS changing RenderStates?



Thanks!
« Last Edit: April 26, 2021, 12:52:47 pm by Tyrendel »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: change View or change RenderStates?
« Reply #1 on: April 28, 2021, 08:12:39 am »
I'm not quite should what you mean with "changing RenderStates", but I assume you mean that you pass in a sf::Transform.
If it doesn't matter from your code perspective, then you can use whatever makes sense to you. In the end it's just some vector math that defines where to render what.

Personally, I'd use transform in combination with transformation (translation, rotation, scale) of an entity and use a view as the camera that moves around the world.

A lunar lander with water? ;D
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Tyrendel

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: change View or change RenderStates?
« Reply #2 on: April 28, 2021, 09:12:52 am »
What I meant is that I used to change the View using set_center, set_size, rotate, and sometimes storing the view somewhere to set it temporary to default View to render stuff like GUI (I drew on RenderTarget without RenderStates specified), and I’ve fully switched to not changing the View but instead changing the Transform stored in a RenderState that I pass along each draw function, and that I can locally change without impacting calling functions (I also use the default RenderState when I want to draw GUI).

I understand from your answer that going one way or the other is globally the same, I just have to decide which way I prefer. Thanks !

Water ? It’s because I didn’t make it to the moon in the video ;-)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: change View or change RenderStates?
« Reply #3 on: April 28, 2021, 09:32:43 am »
With the view's viewport you can achieve things that you can't really with basic transformations, but otherwise it's all just vector math. Not sure if there are OpenGL implications of using one over the other, but I doubt it.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/