Results 1 to 9 of 9

Thread: Fonts

  1. #1
    Member Newbie
    Join Date
    Dec 2002
    Location
    Bucharest, Romania
    Posts
    41

    Fonts

    I have a font which is loaded from a texture. Something like this:


    Of course, different characters have different width. If I write them to the screen using squares and mapping each letter's corresponding square in the texture on that square, then the text will not be equally spaced (the distance between the characters will not be the same).
    For example, the distance between 'Q' and '|' will be greater than the distance between 'Q' and 'A'.
    Is there a way around this "problem"?

  2. #2
    Junior Member Newbie
    Join Date
    Jan 2003
    Posts
    15

    Re: Fonts

    either force the distances to be uniform. (each character takes up 16 pixels) or do what I did. create a file that stores the width's of each character and use that. If you are using windows and the font is generated dynamically then you can use win32 specific calls to get font dimensions.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Fonts

    If you any have a only few works needed for your application you can make texture map's of whole words like "Score" one texture map, "Start" etc...

    You also could make a more complex font routine with data indicating the width of the letter.

    a = 5
    i = 3

    int font_width = { 4, 5, 3, etc.

    then just read each charactor based on that data.


    Originally posted by Sektor:
    I have a font which is loaded from a texture. Something like this:


    Of course, different characters have different width. If I write them to the screen using squares and mapping each letter's corresponding square in the texture on that square, then the text will not be equally spaced (the distance between the characters will not be the same).
    For example, the distance between 'Q' and '|' will be greater than the distance between 'Q' and 'A'.
    Is there a way around this "problem"?

  4. #4
    Member Newbie
    Join Date
    Dec 2002
    Location
    Bucharest, Romania
    Posts
    41

    Re: Fonts

    I thought about this before, but how can I get the width of the characters from the texture?

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,502

    Re: Fonts

    If you want to determine the width of the character from the texture, and the layout of the characters in the texture is a regular grid, then it is easy. For each cell, scan it looking for the minimum and maximum x positions of set pixels in it. Then the difference of those values would be width of the character. Though you will need to add in some extra padding space to that value to make the text not run too close together.

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,502

    Re: Fonts

    If you get the font dimensions from Win32, then it is possible to get perfectly formatted text with kerning and all that jazz.

  7. #7
    Member Newbie
    Join Date
    Dec 2002
    Location
    Bucharest, Romania
    Posts
    41

    Re: Fonts

    I'd like to take the font dimensions from the texture because I have created some fonts using some effects (and the characters' sizes changed).

  8. #8
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Fonts

    You can do into any good pant program and get the number of pixels between charactors.
    May require the use of a piece of paper and just start at the top of the bitmap and work your way down.

    One other way would be since we know the size of each charactor box.
    On say a 8 x 8 box, the center would be 4.
    So say the charactor 'i' center would be charactors_index * 5 + 4.
    Which gives us the center and if its width is 3 then it becomes center +- 1 on each side.

    Hope that makes sense.

    Originally posted by Sektor:
    I'd like to take the font dimensions from the texture because I have created some fonts using some effects (and the characters' sizes changed).

  9. #9
    Senior Member Regular Contributor
    Join Date
    Apr 2001
    Location
    Greece
    Posts
    477

    Re: Fonts

    First consider using monospaced typefaces.They are simpler to use since you can use a constant advance between fonts.Other than that the only sure way to get things right is to get the metrics from the font itself.You can use freetype to do get the metrics and render the fonts to a texture (have a look at the docs if you're interested).You can then also make the borders between the glyphs bigger to accomodate for special fx.Of course you'll have to write your own tool(or find one that suits you,but I doubt you will).Freetype 2 is pretty easy to use though so you might want to give it a shot.

Similar Threads

  1. bitmap fonts vs texture fonts
    By ehsan2004 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-31-2005, 03:24 AM
  2. 3D fonts
    By Arya in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-06-2005, 03:05 PM
  3. fonts
    By incognito in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-06-2002, 01:03 AM
  4. Fonts: HW vs. SW
    By chennes in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 02-22-2001, 12:25 PM
  5. Fonts
    By BrSchnitz in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 09-22-2000, 11:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean