Author Topic: 256px by 256px 64 char bitmap font... help!  (Read 3607 times)

0 Members and 1 Guest are viewing this topic.

Offline ttemper

  • Amiga 1200
  • ****
  • Posts: 267
  • Karma: 7
    • View Profile
256px by 256px 64 char bitmap font... help!
« on: January 07, 2012 »
Ok, so I've spent much time trying to work out how the hell to work this out... and I can't do it.

I thought id change my 2048x32 image back into a 256x256 (8x8 char map @ 32px by 32px char) and try to work out how to calculate when to add 32px onto Y to drop down a line.... but keep the proper offset for X... I'm completely and utterly lost.

Maths isnt my strong point and I'm extremely frustrated, I've tried searching and searching to try and find an example to run off, but for the frustration of me, I still cant work it out. Please help!

The current code is something I pulled from Shockwave's post somewhere on here, which I understand, np... the whole ascii order -32 so it starts at [space], then ! etc.... and then multiply the char by 32 will get the proper 32x32 char... but if it goes >256, thats when I get lost, as I dont know how to drop down by ??px on Y, and keep the correct coordinates on XX.

Like I said, I tried but failed. Im completely stuck being a newbie coder n all, and its just frustrating the hell out of me, especially when i cant find any help text/code anywhere to find out how to do what i want.

Any help is much appreciated to push me in the right direction.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: 256px by 256px 64 char bitmap font... help!
« Reply #1 on: January 07, 2012 »
Say you wanted to print the character 'A' which has code 65.
Then normally your font starts at 32 (space) so subtract that away
Code: [Select]
sprite_number = 65-32 (==33)
Now we know just by looking at our 8x8 bitmap that this is the second character in on the 5th row down.
Counting from 0 that's (1,4), but how do we get there?

Code: [Select]
row_number = round(sprite_number / 8)
column_number = sprite_number % 8

round() means take the whole number part of the result, ie. 4.125 becomes 4.
The % is Modulo or remainder after dividing by 8.  In blitz you'd write
Code: [Select]
sprite_number Mod 8

So you could also write
Code: [Select]
column_number = sprite_number - (row_number * 8)

i.e. 33/8 = 4 remainder 1
and
33 - (4x8) = 1

Once you have row number and column number, multiply them by the size of a character to get the x and y pixels.  If your font is 32 pixels wide, the top left pixel of your font is
32x1, 32x4


Jim

« Last Edit: January 07, 2012 by Jim »
Challenge Trophies Won:

Offline ttemper

  • Amiga 1200
  • ****
  • Posts: 267
  • Karma: 7
    • View Profile
Re: 256px by 256px 64 char bitmap font... help!
« Reply #2 on: January 07, 2012 »
Much thanks Jim, with your help, I did indeed get the subroutine working as it should. I tried to post, but then I lost the whole lot due to a 406 error (doh!), so this time I will keep it short.

Thanks again.

Attached is the code which I used (couldnt paste it in here), so other newbies can learn from it and use it also.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: 256px by 256px 64 char bitmap font... help!
« Reply #3 on: January 07, 2012 »
Thanks for attaching the text that caused the 406 Error.

If you get any more of these, would you mind following the guidelines on the 406 Page please?  It's just so that I can keep all these things in one place (I'm trying to get these issues fixed with our hosts at the moment).  Thanks.
Shockwave ^ Codigos
Challenge Trophies Won: