Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Pro Tip: Using Bitmap Fonts + Working Demo

Author
Message
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 1st Sep 2013 09:35 Edited at: 1st Sep 2013 10:23
The purpose of this post is to help people build better programs.
In this case how to make text look the same on every computer running your games.

This is a working system of using bitmap fonts, complete with 10 prepared fonts which you can paste directly into your game.
Zero mucking around needed. Copy and paste code.




The Problem.
If you ever tried to get someone else to play your game you figured out they can't see your custom fonts.
The built-in system requires you to install windows fonts. Nobody does this.

So I decided I'd solve the problem and finally make a bitmap based text system. This way the game doesn't rely on the windows font system.


Creating Bitmap Fonts.
This could be a real pain in photoshop. Luckily someone posted a free app to make this quick.


This is Bitmap Font Creator written by Hubdule.
Thread Including Download Here:
http://forum.thegamecreators.com/?m=forum_view&t=189225&b=41

All of the fonts in this example were prepared with this app.
You can easily swap in any number of other fonts.


How It Works.


The app creates one big image file with all of the characters.
Then we can split them up in DBP, scale and color them.
A text file is created that stores all of the coordinates to make it easy.


Working Demo.
The demo and all source files can be downloaded on the bottom right.



I've included 10 prepared fonts. Use any scale, any color.
There's a centering text feature built-in too.

You can basically drag and drop it into any DBP project.
Just make sure you put the font folder in your project too.




Further Improvements.
I tried to balance some speed with this, while avoiding the need for people to install plugins.
The text could be anti-aliased better, likely at the cost of speed.
You could also adjust the font image in the font creator.

Sometimes the kerning/spacing is off by a pixel. I've left it in this example again for speed.

I find it's a bit slower than Windows Font based methods, but it's still fast enough for games.


This work is improved and based upon this discussion:
http://forum.thegamecreators.com/?m=forum_view&t=189225&b=41


See my previous tip here...
http://forum.thegamecreators.com/?m=forum_view&t=205649&b=1


Update: Forgot to include transparency support so I added it.

Attachments

Login to view attachments
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 5th Sep 2013 05:17 Edited at: 5th Sep 2013 05:18
No peer review on this one? Such a shame.

Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 5th Sep 2013 12:52
Quote: "No peer review on this one? Such a shame."


Haha

Pro's
Really well written
Greatly described and commented
Demo works without an issue
The apps pretty neat

All round great tutorial in my book

Con's
The speed is the only issue

When it comes to speed, the issue is that there's two of everything that being the original hidden sprites (which there's more of if a full character set) and the pasted sprites. I think you could boost the speed just only using a single sprite and when reading the file, store the size and sprite tex coords and when drawing bfont, update the single sprite and paste it.

"Get in the Van!" - Van B
Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 5th Sep 2013 13:22
Hey thanks mate. BMP fonts are on my to-do list so I will take a good look at your code.

Regards Sph!nx
www.mental-image.net
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 5th Sep 2013 14:09
Looks very comprehensive.

My sprite fonts simply match sprite frames to the ASCII code. EG: ABC = ASC(A), ASC(B), ASC(C) = Set Sprite Frame( ASC(A) ), Set Sprite Frame( ASC(B) ), Set Sprite Frame( ASC(C) ). I also make use of pixel fonts simply because it matches the theme I am going for.

Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 5th Sep 2013 19:40
Quote: "When it comes to speed, the issue is that there's two of everything that being the original hidden sprites (which there's more of if a full character set) and the pasted sprites. I think you could boost the speed just only using a single sprite and when reading the file, store the size and sprite tex coords and when drawing bfont, update the single sprite and paste it."

Will that work? I'm a bit concerned that changing the tex coords a dozen times before a sync might merely create what ever the last letter was when sync is called. I'll try this out later today. Thanks.

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th Sep 2013 14:29
I like the idea of using texture coordinates, I hadn't considered that before. With all the sprites you're creating, wouldn't it be better to use clone sprite instead?

Quote: " I'm a bit concerned that changing the tex coords a dozen times before a sync might merely create what ever the last letter was when sync is called. "

I don't think it should. Cause when you set the coordinates then paste it, that image should already be sent to the pipeline for output. I don't think it references it at the time of drawing. But I can't say I know for sure.

Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 6th Sep 2013 19:52 Edited at: 6th Sep 2013 19:53
Example of what I'm talking about:



"Get in the Van!" - Van B
Burning Feet Man
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 7th Sep 2013 01:01
Mage this looks awesome! Cant' wait to try it.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 7th Sep 2013 11:55 Edited at: 7th Sep 2013 12:26
Quote: "When it comes to speed, the issue is that there's two of everything that being the original hidden sprites (which there's more of if a full character set) and the pasted sprites. I think you could boost the speed just only using a single sprite and when reading the file, store the size and sprite tex coords and when drawing bfont, update the single sprite and paste it."


Quote: "Example of what I'm talking about:"


I have made a modified version of the code that does this. I have posted the code just below. Surprisingly I found that hidden sprites even moved off screen drag down frame rate in some small way just by existing. The problem is adjusting texture coordinates on each character draw to try and use only one sprite creates a comparable drag on frame rate. Then add the fact that there's 10 fonts here and in a game I would reduce that to 1 or 2. When I do this then the original code seems to be edging the modified code out. With 10 fonts they are neck and neck.



Quote: "I like the idea of using texture coordinates, I hadn't considered that before. With all the sprites you're creating, wouldn't it be better to use clone sprite instead?"

There is no benefit in this case.


Quote: "... Cause when you set the coordinates then paste it, that image should already be sent to the pipeline for output. I don't think it references it at the time of drawing. But I can't say I know for sure."

yes but doing it all that way seems to trade one type of performance overhead for another. I am wrestling with the tradeoffs.


Quote: "Mage this looks awesome! Cant' wait to try it. "

Great, just glad to help.

Login to post a reply

Server time is: 2024-04-19 06:48:14
Your offset time is: 2024-04-19 06:48:14