PROGRAMMING > Freebasic

Variable Width Bitmap Font Help

(1/3) > >>

ttemper:


In my learning about bitmap fonts and how to lay them out in ascii order as well as a grid pattern with all the same size character width and height, I wanted to see if I could do a variable width bitmap font.

As you can see by the code and the binary, I got it working as I wanted. I know this isn't the best way in doing it, but for an initial test, I got it to work proper.

The main character grids are 64x64px, but like the letter ! and I etc, I only have them at width 19px (background colour is not drawn), starting at the utmost left/top border of the characters 64x64px grid. I then feed this 19px into the scroller routine to only jump the 19px instead of the full 64px, then also run the same loop (for some reason the XJ variable wouldn't parse into the draw routine) for the draw routine.

As I said, this works great. Seeing my screen is 640px wide. so 640/64 = 10 characters on screen at any one time... but now seeing I have the width varied, I need to use the lowest width available which is 19px. so 640/19 = 34 (rounded) chars on screen at any one time + 1 for rendering off screen, so I set this to 35 chars.

I did this in case I end up doing a text of 'oh yeh!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" for eg. hehe, so it wouldn't pre blit/render directly on screen which looked ugly. So in the attempt to do it, if most of my chars are 64px wide, then i'ts pre rendering 25 chars off screen, not 1.

Question..

Is there a way to calc whats already on screen pixel wise on the X res, as the chars are variable width, so I only pre render 1 char off screen on the right instead of 25?

Is there a better way/loop/whatever that I can do this character checking based on render-able pixel width in the bitmap than what I have done in code already?

I'm sure this has been done 10001 times before, but being a newbie, this is... well, all new to me ;P

Thanks in advance.

Bin + Source attached.

hellfire:
Can't you just draw the part of the character that's actually required?


ttemper:
@hellfie, probably could, that's why I asked :)

Not sure who here has dealt with a variable width bitmap font before, but any help/insight is appreciated.

At the moment it just takes the full 64x64 block of character and then eliminates the background colour, then I set the width based on the printable character into variable XJ.

Raizor:
This topic might be relevant, I only had a quick scan.

Google often kicks up old threads on here when searching for something. It's often more effective than using the internal forum search. This came from a search for "freebasic variable width bitmap font" on Google.

ttemper:
@Raizor, thanks. I did search and stumble upon that post and did have a quick read of it. I then still wanted to post my own topic based on the brief test code I did (which works), but I wanted other more knowledgeable coders on here to give me heads up on if I actually did the method 'proper' so to speak, and if so or if not, how would one (or how would yourself do it) go about changing it up in loops to actually get the render-able widths 'on the fly' dependent on the character being represented instead of the full 64px by 64px character block being used.

Navigation

[0] Message Index

[#] Next page

Go to full version