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

Author Topic: Spacing error  (Read 6044 times)

0 Members and 1 Guest are viewing this topic.

ineed.help

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Spacing error
« on: May 30, 2014, 06:59:24 pm »
...
« Last Edit: May 31, 2014, 08:28:48 am by ineed.help »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Line spacing error
« Reply #1 on: May 30, 2014, 07:59:45 pm »
What you're after is called "kerning".  The term "line spacing" refers to the vertical space between lines.

You can access a font's kerning information through sf::Font::getKerning().


But all that aside, why not use sf::Text?  You don't appear to be doing anything it doesn't support.
« Last Edit: May 30, 2014, 08:01:17 pm by Ixrec »

math1992

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
    • Email
Re: Line spacing error
« Reply #2 on: May 30, 2014, 08:04:26 pm »
Also rather than using
xPos += 12;
, the glyph class provide an advance value for each glyph.

ineed.help

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Re: Line spacing error
« Reply #3 on: May 30, 2014, 08:11:38 pm »
I don't think I understand. Aside from me using incorrect terminology, what exactly am I doing wrong?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Spacing error
« Reply #4 on: May 30, 2014, 08:15:05 pm »
You aren't using sf::Font::getKerning() or sf::Glyph::advance.  That's all.

If you don't know what those things mean then read the documentation and/or google some introductions to font metrics.


And again, why not just use sf::Text?  Drawing text correctly is complicated and error-prone, so let SFML do it for you if you don't need anything special.

ineed.help

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Re: Spacing error
« Reply #5 on: May 30, 2014, 08:46:53 pm »
I am using multiple sf::Text instances because I am going to add something (such as sf::sleep) to make the text show one letter at a time.

I have read the documentation and I still don't understand - do you think you could explain it to me?

dabbertorres

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • website/blog
Re: Spacing error
« Reply #6 on: May 30, 2014, 09:19:04 pm »
Why not use one sf::Text and just add a letter to it every few ms? That way you draw MUCH less.

ineed.help

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Re: Spacing error
« Reply #7 on: May 30, 2014, 09:39:25 pm »
Why not use one sf::Text and just add a letter to it every few ms? That way you draw MUCH less.
It doesn't work when I'm using colors and text styles.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Spacing error
« Reply #8 on: May 30, 2014, 09:44:16 pm »
I have read the documentation and I still don't understand - do you think you could explain it to me?

If you ask some more specific questions, yes.  Any general explanation I try to write will be no different from copy-pasting the documentation.


When you say "using colors and text styles", how complicated are we talking?  It's likely you can still do a lot better than separate sf::Texts for every letter.

For the record, there's no point whatsoever in using an sf::Text for a single letter.  It's exactly the same as an Sprite at that point.  The big benefit of sf::Text is that it figures out how to position and render all the letters for you so you don't have to deal with individual glyphs.

ineed.help

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Re: Spacing error
« Reply #9 on: May 30, 2014, 09:58:58 pm »
I need every character to have separate color and style data. How can I accomplish that with sf::Sprite instances? I can't see a way to use a glyph for a sprite, so I don't know what to do.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Spacing error
« Reply #10 on: May 30, 2014, 10:19:21 pm »
sf::Font contains a texture.  sf::Glyph contains a texture rect which corresponds to the glyph's position in that texture once rendered.  The logic in sf::Text that you're essentially duplicating is all about computing a position (though obviously it uses kerning and line spacing and glyph advance and all that stuff).

An sf::Sprite is (very literally) nothing but four vertices, a texture, and a texture rect.


By the way, you can always look at the source code for sf::Text, since you're basically trying to reimplement it.
« Last Edit: May 30, 2014, 10:25:00 pm by Ixrec »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Spacing error
« Reply #11 on: May 30, 2014, 11:00:02 pm »
You need to take the height of each glyph into account too.  With sprites the origin is the top left corner, but I believe with text it's the left end of the "baseline" (google it), so "shorter" glyphs need to be moved down.

There are a lot of different font metrics.  And this is just for English.
« Last Edit: May 30, 2014, 11:02:45 pm by Ixrec »

ineed.help

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Re: Spacing error
« Reply #12 on: May 31, 2014, 08:14:03 am »
EDIT:
I got it now, thank you very much for your help!
« Last Edit: May 31, 2014, 09:47:08 am by ineed.help »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Spacing error
« Reply #13 on: May 31, 2014, 10:47:06 am »
Removing your first post was a very bad idea. Now nobody can understand what's going on in this discussion. Don't do that again please.
Laurent Gomila - SFML developer

Syntactic Fructose

  • Jr. Member
  • **
  • Posts: 80
  • Overflowing stacks and eating snacks
    • View Profile
Re: Spacing error
« Reply #14 on: May 31, 2014, 06:45:11 pm »
Removing your first post was a very bad idea. Now nobody can understand what's going on in this discussion. Don't do that again please.

you stole the words from my mouth. It's a bummer when questions like these show up in google searches and suddenly the post is empty.