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

Author Topic: Best way to draw at pixel position instead of world position?  (Read 2795 times)

0 Members and 2 Guests are viewing this topic.

lmorsino

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Best way to draw at pixel position instead of world position?
« on: October 05, 2014, 10:38:29 am »
What is the best way to draw an object at a specific pixel location rather than world position? I want to draw a sf::Text in one corner regardless of zoom, rotation, translation of the main view or the size of the window. So far, I have done this:

sf::View savedView = window.getView();
sf::View tempView;
tempView.reset(sf::FloatRect(0, 0, window.getSize().x, window.getSize().y));
// ....
window.setView(tempView);
window.draw(text);
window.setView(savedView);
 

This works, but is it the recommended way? Is there a faster/better way?

Thanks,
lmorsino


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Best way to draw at pixel position instead of world position?
« Reply #2 on: October 05, 2014, 11:12:00 am »
Yes, using another view is the recommanded way, as stated in the tutorial.
Laurent Gomila - SFML developer

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Best way to draw at pixel position instead of world position?
« Reply #3 on: October 05, 2014, 03:01:58 pm »
If you want it at pixel position and using pixels for size etc., use the different view as Laurent suggested.
If you want it at pixel position but using your normal view for size etc., use the same view and convert the coordinates as Ixrec suggested.
 :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

didii

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: Best way to draw at pixel position instead of world position?
« Reply #4 on: October 05, 2014, 06:24:40 pm »
As far as I know, changing the view will only translate/scale everything you draw next. Thus using setView is not compute intensive.

 

anything