Another Plugin: SpriteFont Renderer. Native Bitmap Fonts.

Started by Calin Leafshade, Fri 02/09/2011 21:30:53

Previous topic - Next topic

Calin Leafshade

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: ags

//sets a fixed width font
void SetSpriteFont(int fontNum, int sprite, int rows, int columns, int charWidth, int charHeight, int charMin, int charMax, bool use32bit)


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: ags

SetSpriteFont(0, 1,  3, 20, 16, 16, 32, 91, true);


Code: ags

void SetVariableSpriteFont(int fontNum, int sprite);


This overrides font 'fontNum' with sprite 'sprite'

Code: ags

void SetSpacing(int fontNum, int spacing)


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

Code: ags

void SetGlyph(int fontNum, int charNum, int x, int y, int width, int height)


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:


Ghost

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!

Calin Leafshade

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

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.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Calin Leafshade

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

Updated to support variable width fonts

See first post.

Dualnames

Quote from: Calin Leafshade on Sat 03/09/2011 21:26:41
Updated to support variable width fonts

See first post.

I stand corrected. And I edited my post. :D :D :D
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Knox

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

Bugs are possible so bug reports would be nice if anyone tries it out.

Monsieur OUXX

Thanks for the variable width functions. That will come handy.
 

David Ostman

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

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.

Icey

yay! I wasn't even aware of this topic. Now I can try and use that font.

StillInThe90s

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

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.


None

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: AGS

SetSpriteFont(0, 57, 6, 16, 10, 10, 32, 126, false);
  SetSpacing(0, 1);
  SetGlyph(0, 32, 0, 0, 4, 7); //Blank
  SetGlyph(0, 33, 10, 0, 2, 7); //!
  SetGlyph(0, 34, 20, 0, 5, 7); //"
  SetGlyph(0, 35, 30, 0, 6, 7); //#
  SetGlyph(0, 36, 40, 0, 4, 7); //$
  SetGlyph(0, 37, 50, 0, 6, 7); //%
  SetGlyph(0, 38, 60, 0, 4, 7); //&
  SetGlyph(0, 39, 70, 0, 3, 7); //'
  SetGlyph(0, 40, 80, 0, 4, 7); //(
  SetGlyph(0, 41, 90, 0, 4, 7); //)
  SetGlyph(0, 42, 100, 0, 6, 7); //*
  SetGlyph(0, 43, 110, 0, 4, 7); //+
  SetGlyph(0, 44, 120, 0, 3, 7); //,
  SetGlyph(0, 45, 130, 0, 4, 7); //-
  SetGlyph(0, 46, 140, 0, 4, 7); //.
  SetGlyph(0, 47, 150, 0, 5, 7); // /
  //Row2
  SetGlyph(0, 48, 0, 10, 5, 7); //0
  SetGlyph(0, 49, 10, 10, 5, 7); //1
  SetGlyph(0, 50, 20, 10, 5, 7); //2
  SetGlyph(0, 51, 30, 10, 5, 7); //3
  SetGlyph(0, 52, 40, 10, 5, 7); //4
  SetGlyph(0, 53, 50, 10, 5, 7); //5
  SetGlyph(0, 54, 60, 10, 5, 7); //6
  SetGlyph(0, 55, 70, 10, 5, 7); //7
  SetGlyph(0, 56, 80, 10, 5, 7); //8
  SetGlyph(0, 57, 90, 10, 5, 7); //9
  SetGlyph(0, 58, 100, 10, 2, 7); //:
  SetGlyph(0, 59, 110, 10, 3, 7); //;
  SetGlyph(0, 60, 120, 10, 4, 7); //<
  SetGlyph(0, 61, 130, 10, 4, 7); //=
  SetGlyph(0, 62, 140, 10, 4, 7); //>
  SetGlyph(0, 63, 150, 10, 4, 7); // ?
  //Row3
  SetGlyph(0, 64, 0, 20, 8, 7); //@
  SetGlyph(0, 65, 10, 20, 5, 7); //A
  SetGlyph(0, 66, 20, 20, 5, 7); //B
  SetGlyph(0, 67, 30, 20, 5, 7); //C
  SetGlyph(0, 68, 40, 20, 5, 7); //D
  SetGlyph(0, 69, 50, 20, 5, 7); //E
  SetGlyph(0, 70, 60, 20, 5, 7); //F
  SetGlyph(0, 71, 70, 20, 5, 7); //G
  SetGlyph(0, 72, 80, 20, 5, 7); //H
  SetGlyph(0, 73, 90, 20, 4, 7); //I
  SetGlyph(0, 74, 100, 20, 5, 7); //J
  SetGlyph(0, 75, 110, 20, 5, 7); //K
  SetGlyph(0, 76, 120, 20, 5, 7); //L
  SetGlyph(0, 77, 130, 20, 6, 7); //M
  SetGlyph(0, 78, 140, 20, 6, 7); //N
  SetGlyph(0, 79, 150, 20, 5, 7); //O
  //Row4
  SetGlyph(0, 80, 0, 30, 5, 7); //P
  SetGlyph(0, 81, 10, 30, 6, 7); //Q
  SetGlyph(0, 82, 20, 30, 5, 7); //R
  SetGlyph(0, 83, 30, 30, 5, 7); //S
  SetGlyph(0, 84, 40, 30, 6, 7); //T
  SetGlyph(0, 85, 50, 30, 5, 7); //U
  SetGlyph(0, 86, 60, 30, 6, 7); //V
  SetGlyph(0, 87, 70, 30, 6, 7); //W
  SetGlyph(0, 88, 80, 30, 6, 7); //X
  SetGlyph(0, 89, 90, 30, 6, 7); //Y
  SetGlyph(0, 90, 100, 30, 5, 7); //Z
  SetGlyph(0, 91, 110, 30, 3, 7); //[
  SetGlyph(0, 92, 120, 30, 5, 7); // \
  SetGlyph(0, 93, 130, 30, 3, 7); //]
  SetGlyph(0, 94, 140, 30, 4, 7); //^
  SetGlyph(0, 95, 150, 30, 4, 7); //_
  //Row5
  SetGlyph(0, 96, 0, 40, 3, 7); //`
  SetGlyph(0, 97, 10, 40, 5, 7); //a
  SetGlyph(0, 98, 20, 40, 5, 7); //b
  SetGlyph(0, 99, 30, 40, 5, 7); //c
  SetGlyph(0, 100, 40, 40, 5, 7); //d
  SetGlyph(0, 101, 50, 40, 5, 7); //e
  SetGlyph(0, 102, 60, 40, 5, 7); //f
  SetGlyph(0, 103, 70, 40, 5, 7); //g
  SetGlyph(0, 104, 80, 40, 5, 7); //h
  SetGlyph(0, 105, 90, 40, 2, 7); //i
  SetGlyph(0, 106, 100, 40, 4, 7); //j
  SetGlyph(0, 107, 110, 40, 4, 7); //k
  SetGlyph(0, 108, 120, 40, 2, 7); //l
  SetGlyph(0, 109, 130, 40, 6, 7); //m
  SetGlyph(0, 110, 140, 40, 5, 7); //n
  SetGlyph(0, 111, 150, 40, 5, 7); //o
  //Row6
  SetGlyph(0, 112, 0, 50, 5, 7); //p
  SetGlyph(0, 113, 10, 50, 5, 7); //q
  SetGlyph(0, 114, 20, 50, 5, 7); //r
  SetGlyph(0, 115, 30, 50, 5, 7); //s
  SetGlyph(0, 116, 40, 50, 4, 7); //t
  SetGlyph(0, 117, 50, 50, 5, 7); //u
  SetGlyph(0, 118, 60, 50, 6, 7); //v
  SetGlyph(0, 119, 70, 50, 6, 7); //w
  SetGlyph(0, 120, 80, 50, 5, 7); //x
  SetGlyph(0, 121, 90, 50, 5, 7); //y
  SetGlyph(0, 122, 100, 50, 5, 7); //z
  SetGlyph(0, 123, 110, 50, 4, 7); //({)
  SetGlyph(0, 124, 120, 50, 3, 7); //|
  SetGlyph(0, 125, 130, 50, 4, 7); //(})
  SetGlyph(0, 126, 140, 50, 5, 7); //"
  SetGlyph(0, 127, 150, 50, 5, 7); //~

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

use the function for variable width fonts. currently you are using the fixed width font function.

None

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

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?

SMF spam blocked by CleanTalk