BASIC

Author Topic: Bitmapped Font Functions - Everything but the kitchen sink!  (Read 18449 times)

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
You where right, speed improved vastly even from reading from a file, now it's taking about 2% of the old time to load. What would be better for future improvements and multiple fonts, data statements or binary files to save the kern data?

Updated the code, download either from my homepage or the link earlier in the thread.
« Last Edit: 2008-Aug-09 by Moru »

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
Data statements would be neater, as they would be hard coded into the project, and would save having extra files - however, it would mean that you could not write routines to use within any project, as each one would need it's own data coded in, whereas using a separate file means that another program could generate them in advance.

However, with that said, with a little careful coding, it would be possible to export the data into a .gbas named file with DATA statements - hmmm, that is giving me a few ideas ...... ;)
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
My code is generating both data statements and binary files but I don't know how to dynamicly access a certain data statement. We need that if we want several fonts I think?

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
Simple - while creating the data statements for each font, also add in a point for the restore command to refer to - then you can switch fonts in a fraction of a second. Alternatively, read all the data in one go, and store it in a 2D array - kern[font,character]
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
What I meant was, can I have restore points that the user can choose ReadKern("my_font",5) or something similar. No I guess not. I will look into making it one big array later when I have time :-)

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
I'm still thinking about my original code (to be honest, I haven't even looked at the revamped version, apart from the very first one where PV was used for colouring), and indeed, if I do look at doing a modification, I'll be using my old code and starting again, so we could end up with 2 different solutions to achieve the same thing (which is no bad thing!)

As for the inline DATA statements, yes, you can create restore points (just as I did for Manic Miner level data) thus:-

Code: GLBasic [Select]
STARTDATA KERN01
DATA .............
ENDDATA

STARTDATA KERN02
DATA ..........
ENDDATA

Unfortunately, as yet, GL doesn't support calculated restore points, so in the main code, you would need a SELECT / CASE system (again, as I used in ManicMiner) thus:-

Code: GLBasic [Select]
FUNCTION GetKern(fontnum)
SELECT fontnum
CASE 1; RESTORE KERN01
CASE 2; RESTORE KERN02
ENDSELECT

//now read the data for one font

ENDFUNCTION

However, I suspect I would be more likely to use the idea of reading all the data into one 2D array, since the chances of wanting more than 2 or 3 different fonts is highly unlikely (or whatever it is you are working on will just look a total mess!)
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
1) The original links are dead - but I intend on adding a load of useful routines to my webby at some point. I had to stop direct linking to files from other websites, as I was being leeched to death! I will sort that out when I update the font routines (promise!)

2) Mine will work fine with arrays, for one simple reason - each character is only using one byte. So, for the 96 characters I was using, even if you need as many as 5 separate fonts (which is highly unlikely!), the array would still only be [5,96]. The biggest drain of resources will be having the graphics for the fonts preloaded, but that is a necessary evil, or you will be constantly making calls to the hard drive.

3) Since my solution was using bitmap images, you can use windoze fonts, though I would recommend doing it manually in a paint package, since the code relies on the characters being in a particular position within the image strip for the kern to work correctly.

I saw your font routines, but was rather concerned about the sheer amount of data you have - presumably you are storing the font pixel by pixel, which is great for the sparkly effect, but not so great for flexibility when it comes to using different fonts!

I have a WIP I want to finish before I look at revamping the font routines, so you're going to have to bear with me :)
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
I just finnished the multi-font package, download at my homepage and come with suggestions. I would like to make the calling of the functions easier but I'm not sure if I should create extra functions that accept a type instead of lots of parameters, and then call the normal functions from there? What do others think?

Something like this mabe?
Code: GLBasic [Select]
font.color = rgb(255,255,0)
font.shadow = 2
font.shadowalpha = -.4

oDrawText("Testing", font)

function oDrawText: txt$, font as FONT
    DrawText(txt$, font.color, font.shadow, font.shadowalpha)
endfunction
 

Also, does anyone know why I can't have the color black when I draw the polyvectors? It just becomes transparent. Is that mabe because I'm using black as transparent color? I thought that was handled before you draw the texture?

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10709
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
how about wrapping it in functions. That's the way all GLBasic functions work:

FontSetColor(font_index, RGB(0,0,0) )
FontSetShadow(font_index, TRUE, alpha)
FontDrawText("text", font_index)

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
thats how we do it now, it's just that some functions ends up with more paramenters than others and after 14 it starts to be tricky to say the least :-)
« Last Edit: 2008-Aug-11 by Moru »

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10709
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
No, you must split such functions into several functions now. Try to find a partial group that makes sense.

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
Just so you know, I have started tinkering, and have written the first program, which is the program to generate all the data into a nice gbas file ready for copy and pasting, or simply adding to your project. I have tried to make it as open ended as possible so it can deal with any number of fonts that you throw at it (though it will need some manual editing to tell the program how many fonts, and the character sizes of each font.)  No code to look at yet, though - you're going to have to be patient! :D
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
Ok, I guess I create another thread so not to confuse our versions of the same code :-)

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
Hi Peejay,
Im interested if youre doing more with your library?
 This font library you made is really good stuff, and well thought...I Thought you might find interesting..Gernot added the BYREF option, for passing data in/out of functions now...you can pass data around like a football!

Hows your WIP coming along? Is it for GLBasic or the internet?
« Last Edit: 2008-Oct-12 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
I did make a good start on revamping the library, but then after a bit of a disagreement with another site, I haven't done any coding for a while. I'm sure I'll get back to it at some point though .....
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity