Bitmap font

A little while ago there was a tool called GlyphDesigner released by 71squared. The app is for the mac and allows you to design cool effects for fonts you have on your computer. The tool is really good and I wonder you can add support for that tool so corona reads font files created by GlyphDesigner? [import]uid: 34126 topic_id: 6060 reply_id: 306060[/import]

Awesome, thanks.

I made arial32.fnt file and a .png in GlyphDesigner and tried it with your code but when I ran it in the simulator I got this error;

Runtime error
…1HGkKXNH+WWf6ydHU3uW++++TI/TemporaryItems/48/bmf.lua:71: ERROR: Invalid parameter passed to sprite.newSpriteSheetFromData(). Missing data.
stack traceback:
[C]: ?
[C]: in function
‘newSpriteSheetFromData’
…1HGkKXNH+WWf6ydHU3uW++++TI/TemporaryItems/48/bmf.lua:71: in function ‘loadFont’
…HGkKXNH+WWf6ydHU3uW++++TI/TemporaryItems/48/main.lua:13: in main chunk

Runtime error: …1HGkKXNH+WWf6ydHU3uW++++TI/TemporaryItems/48/bmf.lua:71: ERROR: Invalid parameter passed to sprit
e.newSpriteSheetFromData(). Missing data.
stack traceback:
[C]: ?
[C]: in function ‘newSpriteSheetFromData’
…1HGkKXNH+WWf6ydHU3uW++++TI/TemporaryItems/48/bmf.lua:71: in function ‘loadFont’
…HG
kKXNH+WWf6ydHU3uW++++TI/TemporaryItems/48/main.lua:13: in main chunk
Do you have any ideas why this happen? I have the .fnt file and the .png in the same directory as the main.lua and the bmf.lua

I just copied your code and made the bmf.lua file and copied the other code into my main.lua. Do I have to make a spriteSheet out of my arial.png too? Do I have to slice the all the letters into individual sprites to make a arial32.lua spriteSheet?

How did you make it work?
David [import]uid: 34126 topic_id: 6060 reply_id: 21905[/import]

I got it to work, but I had a strange problem though. I copied everything of your code exactly like in your file you posted for download and when I ran the project I got the error above, but here is the strange part…
when I made a new set of files and replaced the old ones, the project worked???

I tried the old files 20 times and they failed in simulator but when I copied the code and pasted them into new file it built fine, is that a bug in corona or something?

I wish a clean Target/All Targets option were built in Corona Simulator, just like in xcode. [import]uid: 34126 topic_id: 6060 reply_id: 22010[/import]

Are you perhaps using Windows?
(I wouldn’t assume so if you are talking about Glyph Designer, which is a Mac program)
If so, maybe it’s a Windows vs Mac end-of-line marker issue?

I tried freshly downloading and running the zip on my Mac and it doesn’t have issues. [import]uid: 32962 topic_id: 6060 reply_id: 22014[/import]

I got a mac, I’ve been testing some more and it seems to be something wrong with the font I used. I made a few different fonts and there was only that one that didn’t work (materhorn.fnt, 64pt). I only changed the fonts and the rest was the standard presets that starts with glyph designer.

I have no clue what the problem could be? I can sent you the font file.
David

[import]uid: 34126 topic_id: 6060 reply_id: 22023[/import]

Here is a link to my example project, including font file:

http://ember.awirtz.com/bmf.zip

If you are having trouble, you can send me your sample project and I can take a look and see if I can figure out what is being buggy…
[import]uid: 32962 topic_id: 6060 reply_id: 21908[/import]

Thanks for sending the file.

After trial and error removing various lines from the FNT file until I isolated the problem, I discovered that the “`” (backtick) character for this font has a negative y-offset.
This confuses some of the math which calculates the spritesheet coordinates.
Also, I noticed that this FNT file has quite a few kernings, which my code currently ignores.
I’m working on updating the code to handle the negative y-offset and adding support for kernings.
In the mean time, if you delete the line for backtick (id=96) from the FNT file, you should be able to start working with your Materhorn.FNT while you are waiting for me. [import]uid: 32962 topic_id: 6060 reply_id: 22049[/import]

I’ve updated my code to support negative offsets, added kerning support, and added support for newlines.

The new code is available at the link above. I also included an Impact-based font rather than the old Futura-based one to demonstrate the kerning support. (Notice that the "W"s and "A"s interlock properly)

One other caveat that I have discovered (technically it could be considered a bug in Glyph Designer) is that if you set the spacing too low (e.g. 0), some of the character x/y coordinates end up negative. Just make sure you have spacing set to at least 1px. [import]uid: 32962 topic_id: 6060 reply_id: 22078[/import]

Merry Christmas…

[edit]
Old code removed - see link below for latest code.
[/edit]

I don’t have the registered version of Glyph Designer to test with, but it works with BMFont output, so it ought to work with Glyph Designer as well.

[edit]
After playing with Glyph Designer, I bought it and exported a font. I discovered and fixed an issue in my code that didn’t like the fact that space was encoded as a 0px by 0px bitmap, and I can now say I have tested it with Glyph Designer output and it works nicely.
[/edit] [import]uid: 32962 topic_id: 6060 reply_id: 21658[/import]

Cool, what does the dumper.lua file do?
Do I have to include that file in my projects when i use bmf? [import]uid: 34126 topic_id: 6060 reply_id: 22081[/import]

No, you don’t. Sorry I didn’t mean to include that in the zip. (removed it now)

It is a Lua library for dumping the contents of data structures to the console so I can see what’s going on inside of them when debugging. [import]uid: 32962 topic_id: 6060 reply_id: 22089[/import]

@p120ph37:
thanks for the bmf.lua file!
i got a glyph designer license now and i am using the bmf.lua file to render a big bitmap font style timer that is updated by a Runtime “enterframe” event handler.
it is a central element of my game and it looks amazing.
–> thanks so far!

the only problem i face now is that when i check for memory leaks with instruments, it seems that the graphics that are created are not deallocated and i get memory warnings/crashes after a while.
i experimented with ‘object:removeSelf()’ and set the variables in my code to nil, it didn’t help.

this is what it looks like:

-- SHOW TIME PLAYED WITH BMP CUSTOM FONT  
  
--initialize bmp font timer:  
local Timestring = bmf.newString(font2, "00:00:00:00")  
Timestring.x = 55  
Timestring.y = 70  
--update bmp font timer:  
function TimestringUpdate (newString)  
Timestring:removeSelf()  
Timestring = nil  
Timestring = bmf.newString(font2, newString)  
Timestring.x = 55  
Timestring.y = 70   
newString=nil  
end  
  
--newString parameter comes from another function   
-- this is called by a runtime "enterframe"event listener  

now i think maybe it is happening inside the bmf.lua file?
when you return the font object in the newString function, is there a way to clean up the memory after it returned the object?
Big Thanks! [import]uid: 34449 topic_id: 6060 reply_id: 24405[/import]

I edited the code a little so it only draws a new picture every 50ms.
helps a little because now it uses up the memory much slower, but doesn’t solve the problem.
[import]uid: 34449 topic_id: 6060 reply_id: 24431[/import]

Thanks for the feedback - So far I have used it mostly for fairly low-refresh things so I hadn’t seen the memory leak issues. I will look into it when I get a chance. Can you provide me with the debug statements you are using to track the memory usage too?

In the mean time, I have some minor updates of my own that I’ve made to the BMF library while working on my own projects, which I have uploaded to the ZIP. I fixed an off-by-one issue with spritesheet alignment, added support for newlines, and added placeholder rectangles so that the text centers correctly when there are leading/trailing spaces or blank lines. [import]uid: 32962 topic_id: 6060 reply_id: 24499[/import]

Actually, I think I’ve located the issue. ( I took your example code and fed it system.getTimer() data every frame while monitoring the value of collectgarbage( ‘count’ ) )

It seems that Corona does not automatically free the memory used by children of a group object when the group object is removed.

As a work-around, I have overridden the ‘removeSelf’ method of my string objects (really just group objects under the hood) so that it removes its children before removing itself.

Your memory leak should now be gone with the latest version of the library.

Cheers!

NB: If you use the parent:remove( string ) form rather than string:removeSelf(), this will not hit my custom removeSelf method. [import]uid: 32962 topic_id: 6060 reply_id: 24517[/import]

Wow, Great News! I will try it out Tomorrow! [import]uid: 34449 topic_id: 6060 reply_id: 24554[/import]

ahh… download link seems to be broken. could you check? [import]uid: 34449 topic_id: 6060 reply_id: 24617[/import]

works like a charm:

thank you! [import]uid: 34449 topic_id: 6060 reply_id: 25064[/import]

I threw a few more examples and sample fonts into the demo - this should give people something decent to play with before deciding if they want to buy Glyph Designer.

[import]uid: 32962 topic_id: 6060 reply_id: 26372[/import]

This is great, very much help. As an owner of Glyph Designer who likes the look of Text Candy how can I easily convert angelcode .fnt into .lua spritesheet? [import]uid: 6086 topic_id: 6060 reply_id: 28653[/import]