SFML community forums
Help => Graphics => Topic started by: Sparticle on February 07, 2014, 03:39:32 am
-
Hi all,
I'm creating a module which manipulates text using sf::vertices. So far I can create nice gradients, cycle colors and scroll text etc but want to know if there is a way I can apply a different texture to the text' s glyph's and how to go about doing that.
-
I'm fairly certain they have an explanation of how to do this in the SFML tutorial section under "Texts and fonts"(http://www.sfml-dev.org/tutorials/2.1/graphics-text.php (http://www.sfml-dev.org/tutorials/2.1/graphics-text.php)). Unless you need to do something different, of course.
-
Thanks will check it out now.
-
I'm fairly certain they have an explanation of how to do this in the SFML tutorial section under "Texts and fonts"(http://www.sfml-dev.org/tutorials/2.1/graphics-text.php (http://www.sfml-dev.org/tutorials/2.1/graphics-text.php)). Unless you need to do something different, of course.
I've already looked at this tutorial.
It only tells you how to obtain the glyph's texture and coordinates, it doesn't tell you how to change the actual glyph's texture.
For example:-
sf::Font f;
f.loadFromfile("font.ttf");
sf::Texture t = f.getTexture(50);
sf::Glyph g = f.getGlyph('a',50,sf::Text::Bold);
I now have the glyph 'a' texture and coordinates.
What i want to know is how to change the glyph's texture to say, the texture of a brick wall or something else.
Thanks.
-
You can't directly change the contents (glyph, texture) of a sf::Font. You must write your own custom font class.
-
You can't directly change the contents (glyph, texture) of a sf::Font. You must write your own custom font class.
Thanks for the reply.
I understand that you can't directly change the contents of glyph's and the fonts texture.
My idea was to copy the fonts texture containing all the glyph's needed in to my own texture.
Then somehow change the characters contained in it with a different fill from another texture.
A bit like a stencil.
-
Ok, so that should be easy to do if you have the texture and area to modify. What's your problem exactly?
-
Ok, so that should be easy to do if you have the texture and area to modify. What's your problem exactly?
Thanks again.
The problem is figuring out how fill the glyph's contained in the copied texture with a different fill from another texture.
Is there an easy way to do this?
-
It really depends what you imagine under "fill from another texture". If you want a completely different font face, then you should either go with implementing your own bitmap font renderer or create a TTF based of your own font. :)
-
If the replacement pixels are available as a simple pixel array, then use this overload of Texture::update (http://www.sfml-dev.org/documentation/2.1/classsf_1_1Texture.php#a1352d8e16c2aeb4df586ed65dd2c36b9).
-
If the replacement pixels are available as a simple pixel array, then use this overload of Texture::update (http://www.sfml-dev.org/documentation/2.1/classsf_1_1Texture.php#a1352d8e16c2aeb4df586ed65dd2c36b9).
Thanks, will try it out.
-
It's been a while since my last post as I've been away .
Anyway, I managed to update the fonts texture with one of my own. I tried the Texture.update() function but it also replaces the transparent pixels too.
Instead I just copied the textures image to another, loop through the array checking for none transparent Pixels, then replacing
them from my own.
The problem is now, as you can see, the textured text is not crisp and smooth like the normal one.
Thanks.
-
The problem is now, as you can see, the textured text is not crisp and smooth like the normal one.
Keep the original alpha, just replace RGB channels.
-
Keep the original alpha, just replace RGB channels.
Silly Me!!
Should of realized to keep the original alpha channel ::)
(http://"ss.png")
Thanks.