SFML community forums

General => Feature requests => Topic started by: mateandmetal on December 18, 2012, 09:36:38 pm

Title: Textured text?
Post by: mateandmetal on December 18, 2012, 09:36:38 pm
Can sf::Text use a texture instead of a solid fill color?

  sf::Text myText ("Hello!", myFont, 35);
  myText.setTexture (myTexture);
 

I know sf::Shape has a setTexture method. Can sf::Text have one?  ::)
Title: Re: Textured text?
Post by: Grimshaw on December 18, 2012, 10:26:28 pm
Each glyph of an sf::Text is really a quad, not an actual character geometry. This means that we can only specify the texcoords of the corners, which we already use to map the actual character in the font texture.

In conclusion, that effect is impossible with the current API, and without a major break in the way that sf::Text and sf::Font work..

Maybe you could achieve it with a pixel shader testing the text geometry by its color and assigning a texture coordinate?
Title: Re: Textured text?
Post by: Laurent on December 18, 2012, 10:40:56 pm
What's the use case for textured text? Why do you need it?
Title: Re: Textured text?
Post by: Chris12 on December 19, 2012, 11:14:53 am
Use a shader to directly merge the two textures (the glyphs and your custom texture) in a single drawcall.
or if that doesnt work draw the text with white color, then in a second pass, apply your texture on all white pixels.
Title: Re: Textured text?
Post by: mateandmetal on December 19, 2012, 05:15:14 pm
Thanks Devil, Chris, but I know nothing about GLSL programming  :-[
Laurent: I want to display textured text in different languages. The strings are loaded from the .xml file at runtime.