BmFont Problems

BlitzMax Forums/BlitzMax Programming/BmFont Problems

CyBeRGoth(Posted 2009) [#1]
Hi

I just found out about this font module from this post
BMFont

But whenever I try the included example I get stream errors, I have been away from max for a bit, perhaps there has been some changes to streams that prevent this mod from working correctly?

Any help getting it working would be appreciated.


matibee(Posted 2009) [#2]
Yes, the stream handling has changed.

A lot of code used a return of zero from a read request as an indicator of eof, but now an empty read throws an exception.

I can't remember where I modified the source, but it was just in one call (I added an eof check before the read that caused the exception). So it's a pretty simple fix if you locate the offending code with a debug build.


matibee(Posted 2009) [#3]
OK, I dug out the original version..

Original, line 277, reads;
BlockType = ReadByte (file)


change it to..
If ( Not Eof( file ) )
  BlockType = ReadByte (file)
Else
  BlockType = 0
End If


and that's it :)


CyBeRGoth(Posted 2009) [#4]
Ah

Thanks a lot matibee that fixed it up nicely :)

Time to have a play around with the mod now!


Imphenzia(Posted 2010) [#5]
I've downloaded the version of BMFont for BlitzMax here http://www.wieringsoftware.nl/blitz/ and made the change matibee suggested.

But I think the code for DrawText in the module needs to be updated with DX9 - does anyone know what needs to be done for that? The graphicsdrivers and singlesurfaces confuse me :)

And not only that, if I do run it with OpenGL or DX7 all the characters are corrupted and unreadable. Does this work for anyone else?


matibee(Posted 2010) [#6]
I fixed it again recently for DX9... http://www.matibee.co.uk/wpsite/?page_id=6/general-2/bitmap-font-mod-revisited/

It no longer supports italics in any graphics driver as it just uses DrawSubImageRect now (a function that didn't exist when it was originally written).

:)


Imphenzia(Posted 2010) [#7]
Great stuff, thanks :)

Also I gather it no longer supports textured fonts? (not a problem for me).

The shadows look funny (inverted) now for both DX9 and OpenGL?




matibee(Posted 2010) [#8]
Ha! I sent this fix back to Mike with the disclaimer attached that it's not been fully tested because I simply don't use all of the features. Stoopid me didn't think of actually running the very sample he provides! :P

I'll have a look what happened to the texturing and shadows.

:)


matibee(Posted 2010) [#9]
Well that was simple enough. Please download again :)


Imphenzia(Posted 2010) [#10]
Thank you very very much Matibee :)

What's the score with using single surface rather than drawimage - is it faster? and if so - much? or are there other benefits?


matibee(Posted 2010) [#11]
Having the fonts packed onto individual textures saves video memory for one thing; every loaded image is rounded up to be power-of-two wide and high. So loading an individual letter that's 9 x 10 pixels (360 bytes) would actually create a texture of 16 x 16 pixels (1024 bytes). With multiple fonts with lots of characters each that would soon add up to a massive waste.

It is generally quicker to draw multiple images all off the same texture because it avoids texture changes on the video card, but the bmfont wasn't necessarily built the way it is because of that because it supports multiple textures per font. Assuming all your fonts are a single texture it'll be a bit quicker than swapping textures every letter.

Before you try compiling sprite sheets of 8096x8096 with every single bitmap you game needs be warned; there is a overhead with accessing large textures and hardware will impose texture size limits.

I'm not a graphics guru, my knowledge on the above stems from years of following good advice and best practices and ultimately, writing some very performant code ;)

The ultimate way to draw a font would be to use one texture and then compile a string into its own vertex buffer that only ever changes when the string does and it can all be drawn in one call. Moving on from that all the string vertex buffers could be merged together to allow drawing reams of text in one call; or even merge all the 2d buffers into one big buffer and only stop drawing to change renderstates..... and on it goes but there's always limitations and trade offs. Right now, Blitz uses one hardware draw call for every software call which isn't ideal but on modern hardware it gets by. Nilium (sp?) was working on a buffered video driver to overcome this.


wmaass(Posted 2010) [#12]
Anyone out there have this working with the latest editor (1.12)? I am using matibee's version of the bmfont mod and can't get it to read the binary fonts generated from the new editor.


skn3(Posted 2011) [#13]
Sorry to dig up an old thread, but does anyone have matibee's modified version of this module?


matibee(Posted 2011) [#14]
It's all here..

http://www.matibee.co.uk/_x/downloads

My site is / was a wordpress site that was getting spammed to bloody hell and I don't have the patience to keep maintaining it.

Last edited 2011


skn3(Posted 2011) [#15]
Thanks matt!


Gonna post the code here:

For years in the future when people come a looking!

Last edited 2011