SFML community forums

Help => Graphics => Topic started by: Sparticle on February 07, 2014, 03:39:32 am

Title: Need some help with primitives please!!!
Post 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.
Title: Re: Need some help with primitives please!!!
Post by: AN71 on February 07, 2014, 03:47:07 am
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.
Title: Re: Need some help with primitives please!!!
Post by: Sparticle on February 07, 2014, 03:56:16 am
Thanks will check it out now.
Title: Re: Need some help with primitives please!!!
Post by: Sparticle on February 07, 2014, 04:35:18 am
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.
Title: Re: Need some help with primitives please!!!
Post by: Laurent on February 07, 2014, 07:39:53 am
You can't directly change the contents (glyph, texture) of a sf::Font. You must write your own custom font class.
Title: Re: Need some help with primitives please!!!
Post by: Sparticle on February 07, 2014, 09:13:23 am
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.
Title: Re: Need some help with primitives please!!!
Post by: Laurent on February 07, 2014, 10:26:20 am
Ok, so that should be easy to do if you have the texture and area to modify. What's your problem exactly?
Title: Re: Need some help with primitives please!!!
Post by: Sparticle on February 07, 2014, 10:46:23 am
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?
Title: Re: Need some help with primitives please!!!
Post by: eXpl0it3r on February 07, 2014, 11:11:13 am
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. :)
Title: Re: Need some help with primitives please!!!
Post by: Laurent on February 07, 2014, 11:44:33 am
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).
Title: Re: Need some help with primitives please!!!
Post by: Sparticle on February 08, 2014, 02:10:14 pm
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.
Title: Re: Need some help with primitives please!!!
Post by: Sparticle on March 12, 2014, 11:41:59 am
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.
Title: Re: Need some help with primitives please!!!
Post by: Laurent on March 12, 2014, 12:24:29 pm
Quote
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.
Title: Re: Need some help with primitives please!!!
Post by: Sparticle on March 13, 2014, 10:57:08 am
Keep the original alpha, just replace RGB channels.

Silly Me!!
Should of realized to keep the original alpha channel ::)

(http://"ss.png")

Thanks.