#include "fbgfx.bi"

  '' The first supported character
Const FirstChar = 0
  '' Last supported character
Const LastChar = 255
  '' Number of characters total.
Const NumChar = (LastChar - FirstChar) + 1


Screenres 640, 480, 32


  '' Create a font buffer large enough to hold 96 characters, with widths of 8.
  '' Remember to make our buffer one height larger than the font itself.
Dim as FB.Image ptr myFont = ImageCreate( ( NumChar * 8 ), 8 + 1 )
  '' Our font header information.
  '' Cast to uByte ptr for safety and consistency, remember.
  '' Make sure to skip the image buffer header!
  '' Now our order is |FB.Image|Font Header|Pixels|
Dim as uByte ptr myHeader = cast(uByte ptr, myFont ) + sizeof(FB.Image)
Print "Font Buffer Created!"
sleep

  '' Assign font buffer header.
  '' Header version
myHeader[0] = 0
  '' First supported character
myHeader[1] = FirstChar
  '' Last supported character
myHeader[2] = LastChar

  '' Assign the widths of each character in the font.
For DoVar as Integer = 0 to NumChar - 1
    '' Skip the header, if you recall
  myHeader[3 + DoVar] = 8  
Next
Print "Header information Assigned!"
sleep

  '' NEW!!!
  '' Our current font character.
Dim as uByte CurChar

  '' Draw our fonts onto our buffer.
For DoVar as Integer = 0 to NumChar - 1
    
    '' Current font character on the ASCII list.
    '' We start at the first character.
  CurChar = DoVar + FirstChar
  
    '' Draw onto our font using FB's default font.
    '' Remember that we can't change our color once we choose it, so be careful
    '' We'll be filling our font with a random color.
  Draw String myFont, ( DoVar * 8, 1 ), chr(CurChar), rgb(rnd * 255, rnd * 255, rnd * 255)
  
    '' Print our current character for clarity.
    '' Note, you probably will hear a beep :D
  Print chr(CurChar);
Next
Print ""
Print ""
Print "Font Drawn onto Font Buffer!"
Sleep

  '' Use our font buffer to draw some text!
Draw String (0, 80), "Hello!", , myFont
Draw String (0, 88), "HOW ARE ya DOIN Today?!  YA DOIN FINE?!", , myFont
sleep

  '' Remember to destroy our image buffer.
ImageDestroy( myFont )