Skip to content

Commit

Permalink
Fix for broken text when the font is reloaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
Foaly committed Jan 15, 2018
1 parent b6c1aca commit 964d759
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/SFML/Graphics/Text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ class SFML_GRAPHICS_API Text : public Drawable, public Transformable
mutable VertexArray m_outlineVertices; ///< Vertex array containing the outline geometry
mutable FloatRect m_bounds; ///< Bounding rectangle of the text (in local coordinates)
mutable bool m_geometryNeedUpdate; ///< Does the geometry need to be recomputed?
mutable Uint64 m_fontTextureId; ///< The fonts texture id
};

} // namespace sf
Expand Down
6 changes: 4 additions & 2 deletions include/SFML/Graphics/Texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@

namespace sf
{
class Window;
class InputStream;
class RenderTarget;
class RenderTexture;
class InputStream;
class Text;
class Window;

////////////////////////////////////////////////////////////
/// \brief Image living on the graphics card that can be used for drawing
Expand Down Expand Up @@ -584,6 +585,7 @@ class SFML_GRAPHICS_API Texture : GlResource

private:

friend class Text;
friend class RenderTexture;
friend class RenderTarget;

Expand Down
7 changes: 5 additions & 2 deletions src/SFML/Graphics/Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,13 @@ void Text::draw(RenderTarget& target, RenderStates states) const
////////////////////////////////////////////////////////////
void Text::ensureGeometryUpdate() const
{
// Do nothing, if geometry has not changed
if (!m_geometryNeedUpdate)
// Do nothing, if geometry has not changed and the font texture has not changed
if (!m_geometryNeedUpdate && m_font->getTexture(m_characterSize).m_cacheId == m_fontTextureId)
return;

// Save the current fonts texture id
m_fontTextureId = m_font->getTexture(m_characterSize).m_cacheId;

// Mark geometry as updated
m_geometryNeedUpdate = false;

Expand Down

0 comments on commit 964d759

Please sign in to comment.