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

Author Topic: Need some help with primitives please!!!  (Read 3689 times)

0 Members and 1 Guest are viewing this topic.

Sparticle

  • Newbie
  • *
  • Posts: 9
    • View Profile
Need some help with primitives please!!!
« 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.

AN71

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Need some help with primitives please!!!
« Reply #1 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). Unless you need to do something different, of course.
Quote from: Friedrich Nietzsche
He who would learn to fly one day must first learn to stand and walk and run and climb and dance; one cannot fly into flying.

Sparticle

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Need some help with primitives please!!!
« Reply #2 on: February 07, 2014, 03:56:16 am »
Thanks will check it out now.

Sparticle

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Need some help with primitives please!!!
« Reply #3 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). 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Need some help with primitives please!!!
« Reply #4 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.
Laurent Gomila - SFML developer

Sparticle

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Need some help with primitives please!!!
« Reply #5 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Need some help with primitives please!!!
« Reply #6 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?
Laurent Gomila - SFML developer

Sparticle

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Need some help with primitives please!!!
« Reply #7 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Need some help with primitives please!!!
« Reply #8 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. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Need some help with primitives please!!!
« Reply #9 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.
Laurent Gomila - SFML developer

Sparticle

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Need some help with primitives please!!!
« Reply #10 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.

Thanks, will try it out.

Sparticle

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Need some help with primitives please!!!
« Reply #11 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Need some help with primitives please!!!
« Reply #12 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.
Laurent Gomila - SFML developer

Sparticle

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Need some help with primitives please!!!
« Reply #13 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 ::)



Thanks.

 

anything