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

Author Topic: sf::Font Change & sf::Text Notification  (Read 19628 times)

0 Members and 1 Guest are viewing this topic.

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Text garbage after Font reload
« Reply #15 on: January 07, 2015, 03:48:14 pm »
Done...
As for sf::Texture: In theory there is no reason why it's private but I don't care about it, since it's possible use (caching in own GL code while using sf::Texture) is waaay more niche than this (own text layout class).

Back to C++ gamedev with SFML in May 2023

select_this

  • Full Member
  • ***
  • Posts: 130
  • Current mood: just ate a pinecone
    • View Profile
    • darrenferrie.com
Re: Text garbage after Font reload
« Reply #16 on: January 08, 2015, 01:12:15 pm »
I hate to nitpick, but it should be 'dirtiness', not 'dirtyness' ;)
Follow me on Twitter, why don'tcha? @select_this

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Text garbage after Font reload
« Reply #17 on: January 08, 2015, 01:56:24 pm »
It should but that is a common misspelling, including in "buffer dirtyness" context. :P
So.. we will see what Laurent says. ;D
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Text garbage after Font reload
« Reply #18 on: January 08, 2015, 02:11:15 pm »
Quote
It should but that is a common misspelling
Hmm... I expected more rigor from you :P

If the correct spelling is "dirtiness" then "dirtiness" must be used.
Laurent Gomila - SFML developer

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Text garbage after Font reload
« Reply #19 on: January 08, 2015, 04:11:55 pm »
Done too. ;)
Have you looked at the if I mentioned?
https://github.com/FRex/SFML/blob/master/src/SFML/Graphics/Text.cpp#L245
Because of the way it is now, every time text gets drawn without a font set, it will reset it's vertices and bounds but I'd say it's OK enough.
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Text garbage after Font reload
« Reply #20 on: January 08, 2015, 04:18:05 pm »
Yes of course, it's more than ok.
Laurent Gomila - SFML developer

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Text garbage after Font reload
« Reply #21 on: January 08, 2015, 06:44:08 pm »
Do you want a pull request for this?
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Text garbage after Font reload
« Reply #22 on: January 08, 2015, 06:56:21 pm »
I'd like to have other opinions, but since there's none, let's do this PR, yes.
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Text garbage after Font reload
« Reply #23 on: January 09, 2015, 11:43:54 am »
If there's no other way, I'm okay with it.
What's the opinion of the others?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Text garbage after Font reload
« Reply #24 on: January 09, 2015, 12:14:00 pm »
So... After re-reading this whole thread again, I still can't see why nobody considered just making sf::Text (yet another) friend of sf::Texture so that it can check m_cacheId itself. Any time font texture data is updated, the sf::Text would check the cache ID and make sure that the geometry is also updated. Yes... it is a bit more conservative (i.e. might update more) than what FRex has proposed, but it is much simpler if you ask me, and more importantly, it doesn't require changes to the public API.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Text garbage after Font reload
« Reply #25 on: January 09, 2015, 12:18:57 pm »
Because:
Quote
There is no reason to make it 100% private because that'd harm any new text layout class that isn't sf::Text because they couldn't check for that.
Laurent Gomila - SFML developer

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Text garbage after Font reload
« Reply #26 on: January 09, 2015, 12:49:50 pm »
But the question now would be: If exposing it through the API is only important for custom text classes, wouldn't the user be able to take care of this themselves? I figured that the original issue was that the SFML classes did not communicate among themselves enough, thus leading to the garbage text. If the user knows when they load a new font, surely they can also notify their own text class to update its geometry as well no?
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Text garbage after Font reload
« Reply #27 on: January 09, 2015, 01:23:27 pm »
Hmm... this is a valid point. Although it might be really complicated for the user to do it externally, instead of relying on a direct feature in sf::Font. But not impossible.
Laurent Gomila - SFML developer

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Text garbage after Font reload
« Reply #28 on: January 09, 2015, 03:28:13 pm »
In theory, you can require users to notify sf::Text too... but it's super tedious. :P
IMO: There is no reason to make sf::Font a friend of sf::Text for this, SFML is supposed to not be an all inclusive toolset so making use of class harder for users (who can't add a friend declaration) seems really counterproductive.
This is not a change BTW, it's a 100% backwards compatible addition, nothing is gone or altered so any 2.x user code will still work.
« Last Edit: January 09, 2015, 03:43:21 pm by FRex »
Back to C++ gamedev with SFML in May 2023

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Text garbage after Font reload
« Reply #29 on: January 09, 2015, 04:22:29 pm »
Well... I still don't know. What sf::Font does now is basically "caching". The problem is that sf::Text assumes that the cache stays valid forever hence it never checked for it's validity (however that might have been implemented). Caching, be it in sf::Texture via the cache ID or now in sf::Font is really an internal detail if you ask me. Having to expose it through the public API just so non-SFML classes can be built on top of this specific implementation doesn't feel right.

Strictly speaking, one could even argue that when you set an sf::Text's font, you promise not to reload it without setting it again. Reloading the font without re-setting it would break that promise since you are in effect "changing the font" without informing (re-setting the font) the sf::Text. This implies that the (m_font != &font) check would have to be removed though, but I honestly can't think of a reasonable use for that check anyway :P.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

 

anything