Author Topic: Another Plugin: SpriteFont Renderer. Native Bitmap Fonts.  (Read 25546 times)

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Ok so a while ago someone (Icey Games i thnk) expressed an interest in using spritefonts because he has totally got the rest of his game down and wanted to add some sparkle.

Now SSH wrote a spritefont module but it was awkward to use since it didnt integrate with the normal ags text functions. This plugin solves that problem.

So you can set a spritefont to override a normal font and just use .Say() or Display() calls and the plugin will draw.

This means you can bypass all the issues with font outlining and stuff just by providing your own, multi coloured, anti aliased, fonts.

Functions

Code: Adventure Game Studio
  1. //sets a fixed width font
  2. void SetSpriteFont(int fontNum, int sprite, int rows, int columns, int charWidth, int charHeight, int charMin, int charMax, bool use32bit)
  3.  

where:

fontNum is the font number you wish to replace.
sprite is the sprite number that contains the sprite font
rows is the number of rows in the font
columns is the number of columns
charWidth is the width of a single character (must all be the same)
charHeight ditto height.
charMin is the lowest ASCII number that the font contains
charMax ditto highest.
use32bit is currently unused and can be either true or false.

the spritefont must be formatted sequentially like this one:



the function for this one would be:

Code: Adventure Game Studio
  1. SetSpriteFont(0, 1,  3, 20, 16, 16, 32, 91, true);
  2.  

Code: Adventure Game Studio
  1. void SetVariableSpriteFont(int fontNum, int sprite);
  2.  

This overrides font 'fontNum' with sprite 'sprite'

Code: Adventure Game Studio
  1. void SetSpacing(int fontNum, int spacing)
  2.  

This allows you to adjust the spacing of a variable width font if its too spread out with drop shadows and stuff

Code: Adventure Game Studio
  1. void SetGlyph(int fontNum, int charNum, int x, int y, int width, int height)
  2.  

This sets a glyph (character) size and location in the spritefont's texture.

I have included a utility which will generate the code for you.

Usage of variable width fonts

- In the archive is a program called SpriteFont.exe. This program will generate variable width sprite fonts for you with shadows and outlines and all kinds of shit.
- The program generates 2 files. The PNG which is the actual font and a file called metrics.xml.
- In the archive there is also AGSSpriteFontGen.exe. This program will take the metrics.xml and convert it to AGSScript that you can copy into your game.

download

The archive contains a demo and all the files needed.

The helper programs need .Net4.0 to run but the plugin itself has no dependencies.

https://dl.dropboxusercontent.com/u/20918686/ags/ags_sprtitefont.zip

What does it look like? Is it better than AGS's normal font renderering?

Yes it is. It looks like this:

« Last Edit: 09 Apr 2015, 22:01 by Dualnames »

Ghost

  • Guest
Looks useful AND easy to use. Downloading now, will report later!

[edit]
Yes, very sweet indeed. Easy to set up and use; and it's really cool to have it "behind the scenes" with all the standard commands still in charge. Thanks for sharing!
« Last Edit: 03 Sep 2011, 01:48 by Ghost »

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Thanks ghost.

Working on variable width fonts now which will make it much more useful for general purpose stuff but its quite challenging for a c++ novice.

Dualnames

  • Local Moderator
  • Rottwheelers
  • Pretty Badass
    • Dualnames worked on a game that was nominated for an AGS Award!
      Dualnames worked on a game that won an AGS Award!
So from what I'm understanding the restraints so far are:

-Standard size for characters (All characters must have the same width and height).
-Order of characters.

Most font sites actually offer a bitmap containing all the characters of a font in that order, but I haven't browsed bitmap fonts for years, so I can't know.
Regardless this is a nice leap forward.
« Last Edit: 03 Sep 2011, 22:32 by Dualnames »
No more military army stuff. I'm alive and back.

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Yes, although the characters dont need the same height *and* width. That is to say that they dont have to be square but al the characters need to be the same as each other.

And yea, the characters have to be horizontally sequential according to the ascii codes. Normally they will start with space (char 32) and end with Z (char 90)

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Updated to support variable width fonts

See first post.

Dualnames

  • Local Moderator
  • Rottwheelers
  • Pretty Badass
    • Dualnames worked on a game that was nominated for an AGS Award!
      Dualnames worked on a game that won an AGS Award!
Updated to support variable width fonts

See first post.

I stand corrected. And I edited my post. :D :D :D
No more military army stuff. I'm alive and back.

Knox

  • Storm Behind The Badge
Dang you Calin!!

Now I have yet another cool thing to add to my ever-expanding/never-ending/forever-bloating project!!

Seems awesome, downloading now :)
--All that is necessary for evil to triumph is for good men to do nothing.

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Bugs are possible so bug reports would be nice if anyone tries it out.

Monsieur OUXX

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Thanks for the variable width functions. That will come handy.
 

Re: Another Plugin: SpriteFont Renderer. Native Bitmap Fonts.
« Reply #10 on: 09 Sep 2011, 06:23 »
This is extremely useful, Calin, thanks a tonne :)

By the way, what kind of license are you providing this under? If it wouldn't be too much trouble, when/if you next update it, could you include a license in the zip?

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: Another Plugin: SpriteFont Renderer. Native Bitmap Fonts.
« Reply #11 on: 09 Sep 2011, 14:26 »
Yea, I'll GPL it or something when I release the code. Everything I do has a *very* liberal license that usually just requires credit.

Jonathan Wedge

  • It's the time of ICEY!!!
Re: Another Plugin: SpriteFont Renderer. Native Bitmap Fonts.
« Reply #12 on: 10 Sep 2011, 04:36 »
yay! I wasn't even aware of this topic. Now I can try and use that font.

Re: Another Plugin: SpriteFont Renderer. Native Bitmap Fonts.
« Reply #13 on: 15 Sep 2011, 16:41 »
Thanks for making an effort Calin! This will be very useful once I get it working properly.
Now, I wonder if someone could have pity and reach out a helping hand to the blind and the deaf of the ags community. I have no idea how to implement this plugin. Is it supposed to work alongside SSHs plugin, or on its own? What code and what files goes where? Do I import the font -png as an ordinary ags sprite?
An open agf -version of the demo might help. Possibly.

Sorry for lowering the intellectual level to kindergarten, everyone.

Khris

  • having to deal with what games are going through
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
    • Khris worked on a game that was nominated for an AGS Award!
Re: Another Plugin: SpriteFont Renderer. Native Bitmap Fonts.
« Reply #14 on: 15 Sep 2011, 22:15 »
It's a replacement for SSH's module and allows native commands like Display to use the sprite font.

Copy the dll in AGS' main directory.
Then open your game and check the Plugins node in the project tree. It should get listed there and after you activate it, you can use the additional commands it provides.
The font sprite is imported as usual.

Calin's opening post should explain the rest.

Re: Another Plugin: SpriteFont Renderer. Native Bitmap Fonts.
« Reply #15 on: 16 Sep 2011, 14:31 »
Got it. Thanks!

Set Glyph Glitch?
« Reply #16 on: 14 Sep 2012, 12:01 »
In a game I'm working on I want to use your plugin, I installed it and created a bitmap font:

It's spaced 10x10 to accomodate the largest characters or 'glyphs' on the sprite-sheet.

Then in function game_start() I put this:
Code: Adventure Game Studio
  1. SetSpriteFont(0, 57, 6, 16, 10, 10, 32, 126, false);
  2.   SetSpacing(0, 1);
  3.   SetGlyph(0, 32, 0, 0, 4, 7); //Blank
  4.   SetGlyph(0, 33, 10, 0, 2, 7); //!
  5.   SetGlyph(0, 34, 20, 0, 5, 7); //"
  6.   SetGlyph(0, 35, 30, 0, 6, 7); //#
  7.   SetGlyph(0, 36, 40, 0, 4, 7); //$
  8.   SetGlyph(0, 37, 50, 0, 6, 7); //%
  9.   SetGlyph(0, 38, 60, 0, 4, 7); //&
  10.   SetGlyph(0, 39, 70, 0, 3, 7); //'
  11.   SetGlyph(0, 40, 80, 0, 4, 7); //(
  12.   SetGlyph(0, 41, 90, 0, 4, 7); //)
  13.   SetGlyph(0, 42, 100, 0, 6, 7); //*
  14.   SetGlyph(0, 43, 110, 0, 4, 7); //+
  15.   SetGlyph(0, 44, 120, 0, 3, 7); //,
  16.   SetGlyph(0, 45, 130, 0, 4, 7); //-
  17.   SetGlyph(0, 46, 140, 0, 4, 7); //.
  18.   SetGlyph(0, 47, 150, 0, 5, 7); // /
  19.   //Row2
  20.   SetGlyph(0, 48, 0, 10, 5, 7); //0
  21.   SetGlyph(0, 49, 10, 10, 5, 7); //1
  22.   SetGlyph(0, 50, 20, 10, 5, 7); //2
  23.   SetGlyph(0, 51, 30, 10, 5, 7); //3
  24.   SetGlyph(0, 52, 40, 10, 5, 7); //4
  25.   SetGlyph(0, 53, 50, 10, 5, 7); //5
  26.   SetGlyph(0, 54, 60, 10, 5, 7); //6
  27.   SetGlyph(0, 55, 70, 10, 5, 7); //7
  28.   SetGlyph(0, 56, 80, 10, 5, 7); //8
  29.   SetGlyph(0, 57, 90, 10, 5, 7); //9
  30.   SetGlyph(0, 58, 100, 10, 2, 7); //:
  31.   SetGlyph(0, 59, 110, 10, 3, 7); //;
  32.   SetGlyph(0, 60, 120, 10, 4, 7); //<
  33.   SetGlyph(0, 61, 130, 10, 4, 7); //=
  34.   SetGlyph(0, 62, 140, 10, 4, 7); //>
  35.   SetGlyph(0, 63, 150, 10, 4, 7); // ?
  36.   //Row3
  37.   SetGlyph(0, 64, 0, 20, 8, 7); //@
  38.   SetGlyph(0, 65, 10, 20, 5, 7); //A
  39.   SetGlyph(0, 66, 20, 20, 5, 7); //B
  40.   SetGlyph(0, 67, 30, 20, 5, 7); //C
  41.   SetGlyph(0, 68, 40, 20, 5, 7); //D
  42.   SetGlyph(0, 69, 50, 20, 5, 7); //E
  43.   SetGlyph(0, 70, 60, 20, 5, 7); //F
  44.   SetGlyph(0, 71, 70, 20, 5, 7); //G
  45.   SetGlyph(0, 72, 80, 20, 5, 7); //H
  46.   SetGlyph(0, 73, 90, 20, 4, 7); //I
  47.   SetGlyph(0, 74, 100, 20, 5, 7); //J
  48.   SetGlyph(0, 75, 110, 20, 5, 7); //K
  49.   SetGlyph(0, 76, 120, 20, 5, 7); //L
  50.   SetGlyph(0, 77, 130, 20, 6, 7); //M
  51.   SetGlyph(0, 78, 140, 20, 6, 7); //N
  52.   SetGlyph(0, 79, 150, 20, 5, 7); //O
  53.   //Row4
  54.   SetGlyph(0, 80, 0, 30, 5, 7); //P
  55.   SetGlyph(0, 81, 10, 30, 6, 7); //Q
  56.   SetGlyph(0, 82, 20, 30, 5, 7); //R
  57.   SetGlyph(0, 83, 30, 30, 5, 7); //S
  58.   SetGlyph(0, 84, 40, 30, 6, 7); //T
  59.   SetGlyph(0, 85, 50, 30, 5, 7); //U
  60.   SetGlyph(0, 86, 60, 30, 6, 7); //V
  61.   SetGlyph(0, 87, 70, 30, 6, 7); //W
  62.   SetGlyph(0, 88, 80, 30, 6, 7); //X
  63.   SetGlyph(0, 89, 90, 30, 6, 7); //Y
  64.   SetGlyph(0, 90, 100, 30, 5, 7); //Z
  65.   SetGlyph(0, 91, 110, 30, 3, 7); //[
  66.   SetGlyph(0, 92, 120, 30, 5, 7); // \
  67.   SetGlyph(0, 93, 130, 30, 3, 7); //]
  68.   SetGlyph(0, 94, 140, 30, 4, 7); //^
  69.   SetGlyph(0, 95, 150, 30, 4, 7); //_
  70.   //Row5
  71.   SetGlyph(0, 96, 0, 40, 3, 7); //`
  72.   SetGlyph(0, 97, 10, 40, 5, 7); //a
  73.   SetGlyph(0, 98, 20, 40, 5, 7); //b
  74.   SetGlyph(0, 99, 30, 40, 5, 7); //c
  75.   SetGlyph(0, 100, 40, 40, 5, 7); //d
  76.   SetGlyph(0, 101, 50, 40, 5, 7); //e
  77.   SetGlyph(0, 102, 60, 40, 5, 7); //f
  78.   SetGlyph(0, 103, 70, 40, 5, 7); //g
  79.   SetGlyph(0, 104, 80, 40, 5, 7); //h
  80.   SetGlyph(0, 105, 90, 40, 2, 7); //i
  81.   SetGlyph(0, 106, 100, 40, 4, 7); //j
  82.   SetGlyph(0, 107, 110, 40, 4, 7); //k
  83.   SetGlyph(0, 108, 120, 40, 2, 7); //l
  84.   SetGlyph(0, 109, 130, 40, 6, 7); //m
  85.   SetGlyph(0, 110, 140, 40, 5, 7); //n
  86.   SetGlyph(0, 111, 150, 40, 5, 7); //o
  87.   //Row6
  88.   SetGlyph(0, 112, 0, 50, 5, 7); //p
  89.   SetGlyph(0, 113, 10, 50, 5, 7); //q
  90.   SetGlyph(0, 114, 20, 50, 5, 7); //r
  91.   SetGlyph(0, 115, 30, 50, 5, 7); //s
  92.   SetGlyph(0, 116, 40, 50, 4, 7); //t
  93.   SetGlyph(0, 117, 50, 50, 5, 7); //u
  94.   SetGlyph(0, 118, 60, 50, 6, 7); //v
  95.   SetGlyph(0, 119, 70, 50, 6, 7); //w
  96.   SetGlyph(0, 120, 80, 50, 5, 7); //x
  97.   SetGlyph(0, 121, 90, 50, 5, 7); //y
  98.   SetGlyph(0, 122, 100, 50, 5, 7); //z
  99.   SetGlyph(0, 123, 110, 50, 4, 7); //({)
  100.   SetGlyph(0, 124, 120, 50, 3, 7); //|
  101.   SetGlyph(0, 125, 130, 50, 4, 7); //(})
  102.   SetGlyph(0, 126, 140, 50, 5, 7); //"
  103.   SetGlyph(0, 127, 150, 50, 5, 7); //~
  104.  
Here I've assigned the sprite font sheet at slot 57 over the default ags 0 font and then manually defined each glyph on the sheet, and this works, the problem is it still seems to be spacing it based on '10-10'. How do I fix this? Can I fix this, it's really depressing me at this point.

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: Another Plugin: SpriteFont Renderer. Native Bitmap Fonts.
« Reply #17 on: 14 Sep 2012, 12:40 »
use the function for variable width fonts. currently you are using the fixed width font function.

Re: Another Plugin: SpriteFont Renderer. Native Bitmap Fonts.
« Reply #18 on: 14 Sep 2012, 12:45 »
THANK YOU, I just TOTALLY overlooked that in the documentation, wtheck. It's 7:00am here and I've been awake for hours trying to finish getting my text-box working. Thanks so much for your quick reply, and awesome addon.

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: Another Plugin: SpriteFont Renderer. Native Bitmap Fonts.
« Reply #19 on: 14 Sep 2012, 12:50 »
Sorry, I haven't examine the plugin very closely, but cannot there be some kind of helper function to evade repeating SetGlyph for 100 times?
Here, in charlescreations's example, we have all glyths arranged in similar fashion, just having different widths. Would it be possible to make a function that takes a number of glyths per row, common spacing and array of glyth widths?